0

I've written a Python 3.6 script that has the following line in it:

os.chdir(os.path.dirname(os.path.abspath(__file__)))

I call the script via a symbolic link and

print(os.getcwd())

directly after it gives me the location of the link but I want the cwd to be where the .py file is.

Every search I did brought me to questions where people had the issue that they wanted it the other way around so to not follow the link but that's what it's doing anyway. I'm a bit confused, since my searches gave me the impression that following the link should be the default behavior. Executing the script directly works perfectly.

By the way, this on a Linux machine.

m_square
  • 13
  • 4

1 Answers1

0

Try This:

import os, inspect

main_path = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
print(main_path)
DRPK
  • 2,023
  • 1
  • 14
  • 27