Is there any difference between:
__file__
and
sys.argv[0]
Because both seem to be doing the same thing: they hold
It's like Sven said.
MiLu@Dago: /tmp > cat file.py
import sys
import blub
print __file__
print sys.argv[0]
MiLu@Dago: /tmp > cat blub.py
import sys
print "BLUB: " + __file__
print "BLUB: " + sys.argv[0]
MiLu@Dago: /tmp > python file.py
BLUB: /tmp/blub.pyc
BLUB: file.py
file.py
file.py
I thought that __file__ was replaced with the filename during a preprocessor step. I was not 100 % sure that's actually the case in Python - but it is in C/C++ and Perl. In Python, this might be different as the __file__ is also correct for compiled Python files (pyc), and there doesn't seem to be any trace of the filename in that file's contents.