Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #16995 > unrolled thread

What happened to module.__file__?

Started bySteven D'Aprano <steve+comp.lang.python@pearwood.info>
First post2011-12-12 00:21 +0000
Last post2011-12-12 16:38 +0000
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  What happened to module.__file__? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-12 00:21 +0000
    Re: What happened to module.__file__? MRAB <python@mrabarnett.plus.com> - 2011-12-12 01:25 +0000
    Re: What happened to module.__file__? Robert Kern <robert.kern@gmail.com> - 2011-12-12 16:38 +0000

#16995 — What happened to module.__file__?

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2011-12-12 00:21 +0000
SubjectWhat happened to module.__file__?
Message-ID<4ee54918$0$11091$c3e8da3@news.astraweb.com>
I've just started using a Debian system, instead of the usual RedHat 
based systems I'm used to, and module.__file__ appears to have 
disappeared for some (but not all) modules.

On Fedora:

[steve@orac ~]$ python -E
Python 2.6.2 (r262:71600, Aug 21 2009, 12:22:21) 
[GCC 4.4.1 20090818 (Red Hat 4.4.1-6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> math.__file__
'/usr/lib/python2.6/lib-dynload/mathmodule.so'



and on Debian squeeze:

steve@runes:~$ python -E
Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> math.__file__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '__file__'


What's going on?



-- 
Steven

[toc] | [next] | [standalone]


#17000

FromMRAB <python@mrabarnett.plus.com>
Date2011-12-12 01:25 +0000
Message-ID<mailman.3524.1323653095.27778.python-list@python.org>
In reply to#16995
On 12/12/2011 00:21, Steven D'Aprano wrote:
> I've just started using a Debian system, instead of the usual RedHat
> based systems I'm used to, and module.__file__ appears to have
> disappeared for some (but not all) modules.
>
> On Fedora:
>
> [steve@orac ~]$ python -E
> Python 2.6.2 (r262:71600, Aug 21 2009, 12:22:21)
> [GCC 4.4.1 20090818 (Red Hat 4.4.1-6)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import math
>>>> math.__file__
> '/usr/lib/python2.6/lib-dynload/mathmodule.so'
>
>
>
> and on Debian squeeze:
>
> steve@runes:~$ python -E
> Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40)
> [GCC 4.4.5] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import math
>>>> math.__file__
> Traceback (most recent call last):
>    File "<stdin>", line 1, in<module>
> AttributeError: 'module' object has no attribute '__file__'
>
>
> What's going on?
>
The documentation for __file__ says: """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."""

Interestingly, none of the versions on Windows that I've tried have
that attribute for the math module. Is it platform-dependent?

[toc] | [prev] | [next] | [standalone]


#17061

FromRobert Kern <robert.kern@gmail.com>
Date2011-12-12 16:38 +0000
Message-ID<mailman.3558.1323707893.27778.python-list@python.org>
In reply to#16995
On 12/12/11 1:25 AM, MRAB wrote:
> On 12/12/2011 00:21, Steven D'Aprano wrote:
>> I've just started using a Debian system, instead of the usual RedHat
>> based systems I'm used to, and module.__file__ appears to have
>> disappeared for some (but not all) modules.
>>
>> On Fedora:
>>
>> [steve@orac ~]$ python -E
>> Python 2.6.2 (r262:71600, Aug 21 2009, 12:22:21)
>> [GCC 4.4.1 20090818 (Red Hat 4.4.1-6)] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>>>>> import math
>>>>> math.__file__
>> '/usr/lib/python2.6/lib-dynload/mathmodule.so'
>>
>>
>>
>> and on Debian squeeze:
>>
>> steve@runes:~$ python -E
>> Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40)
>> [GCC 4.4.5] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>>>>> import math
>>>>> math.__file__
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in<module>
>> AttributeError: 'module' object has no attribute '__file__'
>>
>>
>> What's going on?
>>
> The documentation for __file__ says: """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."""
>
> Interestingly, none of the versions on Windows that I've tried have
> that attribute for the math module. Is it platform-dependent?

It is build-dependent. Windows builds typically have math and several other 
stdlib "extension" modules built into the PythonXY.dll . Unix builds typically, 
but apparently not always, leave mathmodule.so and others as separate extension 
modules.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web