Proper use of __file__

Darren Dale dd55 at cornell.edu
Tue Oct 5 17:06:10 CEST 2004


Would somebody explain how to use __file__? I mean, what information it
carries, and more importantly, when it does and does not exist? A one line
script:

print __file__

will yield the relative path if run from a shell, but will raise NameError
when the script is run interactively from the interpreter. Is this the
intended behavior?

Thanks,
Darren



More information about the Python-list mailing list