5

I've always assumed that the __file__ variable always gave you the current file name, but that doesn't seem to be exactly what it does. Since I've been facing a bug if I assume this to be true.

Someone told me "that __file__ refers to the last module searched" And this seems to be more accurate, but I'd like to know what __file__ is really supposed to do.

I couldn't find anything concrete mentioned in the Python docs. A lot places seem to mention it, but aren't very clear about it.

http://docs.python.org/2/c-api/import.html?highlight=__file__

http://docs.python.org/2/c-api/module.html?highlight=__file__

ffledgling
  • 11,502
  • 8
  • 47
  • 69

1 Answers1

4
 __file__ is the pathname of the file from which the module was loaded, if it was loaded from a file. The __file__ attribute is not present
 for C modules that are statically linked into the interpreter; for
 extension modules loaded dynamically from a shared library, it is the
 pathname of the shared library file.

from here: http://mail.python.org/pipermail/python-dev/2010-February/097461.html

AngelloMaggio
  • 504
  • 5
  • 16