Skip to content Skip to sidebar Skip to footer

Is There A Version Of Os.getcwd() That Doesn't Dereference Symlinks?

Possible Duplicate: How to get/set logical directory path in python I have a Python script that I run from a symlinked directory, and I call os.getcwd() in it, expecting to get

Solution 1:

Workaround: os.getenv('PWD')

Solution 2:

In general this is not possible. os.getcwd() calls getcwd(3), and according to POSIX.1-2008 (IEEE Std 1003.1-2008):

The pathname shall contain no components that are dot or dot-dot, or are symbolic links.

os.getenv['PWD'] is shell-dependent and will not work for example with sh from FreeBSD.

Post a Comment for "Is There A Version Of Os.getcwd() That Doesn't Dereference Symlinks?"