Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Module __file__ attribute in Python 3

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


steve at REMOVE-THIS-cybersource

Aug 29, 2008, 8:21 AM

Post #1 of 4 (102 views)
Permalink
Module __file__ attribute in Python 3

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).

That will mean that there will be no (easy?) way to determine after the
import whether the module was imported from a source file or a compiled
file. I've suggested that the original justification for the patch no
longer applies, and that the secondary purpose of the patch is better
solved by leaving __file__ as it is in Python 2.x, and introducing a new
attribute __source__.

What do people think? There seems to be a little interest on the python-
dev list from a couple of people, but not enough to actually lead to any
action. Does anyone care what m.__file__ is? Does anyone else feel that
this issue is worth pursuing?


--
Steven
--
http://mail.python.org/mailman/listinfo/python-list


exarkun at divmod

Aug 29, 2008, 9:03 AM

Post #2 of 4 (97 views)
Permalink
Re: Module __file__ attribute in Python 3 [In reply to]

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
--
http://mail.python.org/mailman/listinfo/python-list


deets at nospam

Aug 29, 2008, 10:11 AM

Post #3 of 4 (97 views)
Permalink
Re: Module __file__ attribute in Python 3 [In reply to]

> That will mean that there will be no (easy?) way to determine after the
> import whether the module was imported from a source file or a compiled
> file. I've suggested that the original justification for the patch no
> longer applies, and that the secondary purpose of the patch is better
> solved by leaving __file__ as it is in Python 2.x, and introducing a new
> attribute __source__.
>
> What do people think? There seems to be a little interest on the python-
> dev list from a couple of people, but not enough to actually lead to any
> action. Does anyone care what m.__file__ is? Does anyone else feel that
> this issue is worth pursuing?

I'm +1 on this. Introducing __source__ shouldn't break anything, and is a
minor change as the mapping of loaded file to defining file is already
done.

Diez
--
http://mail.python.org/mailman/listinfo/python-list


google at mrabarnett

Aug 29, 2008, 5:31 PM

Post #4 of 4 (90 views)
Permalink
Re: Module __file__ attribute in Python 3 [In reply to]

On Aug 29, 6:11 pm, "Diez B. Roggisch" <de...@nospam.web.de> wrote:
> > That will mean that there will be no (easy?) way to determine after the
> > import whether the module was imported from a source file or a compiled
> > file. I've suggested that the original justification for the patch no
> > longer applies, and that the secondary purpose of the patch is better
> > solved by leaving __file__ as it is in Python 2.x, and introducing a new
> > attribute __source__.
>
> > What do people think? There seems to be a little interest on the python-
> > dev list from a couple of people, but not enough to actually lead to any
> > action. Does anyone care what m.__file__ is? Does anyone else feel that
> > this issue is worth pursuing?
>
> I'm +1 on this. Introducing __source__ shouldn't break anything, and is a
> minor change as the mapping of loaded file to defining file is already
> done.
>
+1. Leave __file__ as it is. Changing it seems an unnecessary break
with previous versions.
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.