Silly import question (__file__ attribute)

M

mh

So on most modules I import, I can access the .__file__ attribute to
find the implementation. ie:'/data1/virtualpython/lib/python2.3/socket.pyc'

This doesn't work on the "thread" module:Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'module' object has no attribute '__file__'

A few questions. Why? Where is thread.py or thread.so? (I can't find
it).

thanks

matt
 
J

Jack Diederich

So on most modules I import, I can access the .__file__ attribute to
find the implementation. ie:
'/data1/virtualpython/lib/python2.3/socket.pyc'

This doesn't work on the "thread" module:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'module' object has no attribute '__file__'

A few questions. Why? Where is thread.py or thread.so? (I can't find
it).
Python 2.4.1 (#2, Mar 30 2005, 21:51:10)
[GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import sys
import thread
sys.modules['thread']
sprat:~# cd ~/src/python-head/Modules/
sprat:~/src/python-head/Modules# ls thread*
threadmodule.c threadmodule.o

It is a built-in module so it doesn't have a .so (dll) or .py file
to mention.

-Jack
 
F

Fredrik Lundh

mh said:
So on most modules I import, I can access the .__file__ attribute to
find the implementation. ie:
'/data1/virtualpython/lib/python2.3/socket.pyc'

This doesn't work on the "thread" module:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'module' object has no attribute '__file__'

A few questions. Why? Where is thread.py or thread.so? (I can't find
it).
True

</F>
 
S

Steven D'Aprano

It is a built-in module so it doesn't have a .so (dll) or .py file
to mention.

Wouldn't it make sense for module.__file__ to be set to None rather than
completely missing in this case?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top