For question 1 use os.getcwd() # get working dir
and os.chdir(r'D:\Steam\steamapps\common') # set working dir
I recommend using sys.argv[0]
for question 2 because sys.argv
is immutable and therefore always returns the current file (module object path) and not affected by os.chdir()
. Also you can do like this:
import os
this_py_file = os.path.realpath(__file__)
# vvv Below comes your code vvv #
but that snippet and sys.argv[0]
will not work or will work wierd when compiled by PyInstaller because magic properties are not set in __main__
level and sys.argv[0]
is the way your exe was called (means that it becomes affected by the working dir).