Reputation: 18870
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
Reputation: 75
Alternatively, if you don't want to use argv
#!/usr/bin/python
import os
print os.path.realpath(__file__)
Upvotes: 4
Reputation: 34527
#!/usr/bin/python
import os
import sys
print os.path.realpath(sys.argv[0])
Upvotes: 3