Module __file__ attribute in Python 3

Jean-Paul Calderone exarkun at divmod.com
Fri Aug 29 12:03:17 EDT 2008


On 29 Aug 2008 15:21:53 GMT, Steven D'Aprano <steve at remove-this-cybersource.com.au> wrote:
>On the python-dev mailing list, a question has be raised about a change
>to module.__file__ in Python 3.
>
>http://www.gossamer-threads.com/lists/python/dev/674923#674923
>
>In Python 2.x, m.__file__ is the name of the file that the module was
>imported from. That file might end with .py, .pyc, .pyo, or even more
>exotic extensions if Python's import mechanism has been customized.
>
>For reasons explained here:
>http://bugs.python.org/issue1762972
>
>Python 3.0 will introduce a patch that makes m.__file__ always specify
>the source file (.py) if it exists, and only if that file doesn't exist
>will it specify the actual file used (.pyc or .pyo).

This seems particularly pointless.  If __file__ were changed to make it
easier to handle by making the value have a more consistent meaning, then
it might be useful.  It sounds like the change is just making the failure
case more obscure and less likely to be noticed during testing, though.

Jean-Paul



More information about the Python-list mailing list