Reputation: 5400
I'm trying to run a python script from a different location than where it is located but I need to reference files where the python script is located. I tried the following:
os.chdir(os.getcwd())
But unfortunately that gets the current working dir of where I ran the script from, not where the script currently lives.
Thanks
Upvotes: 3
Views: 780
Reputation: 601679
You can use
os.path.dirname(__file__)
to get the directory your script is located in.
Upvotes: 5