Hailiang Zhang
Hailiang Zhang

Reputation: 18870

If we execute a symbolic link python script, can we print the path of the real file?

If I execute a python script which is actually a symbolic link linked to the real script from somewhere else, is there anyway we can print the location of the real script?

Upvotes: 2

Views: 1145

Answers (2)

bld
bld

Reputation: 75

Alternatively, if you don't want to use argv

#!/usr/bin/python
import os
print os.path.realpath(__file__)

Upvotes: 4

MK.
MK.

Reputation: 34527

#!/usr/bin/python

import os
import sys

print os.path.realpath(sys.argv[0])

Upvotes: 3

Related Questions