469,271 Members | 1,743 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Silly import question (__file__ attribute)

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

This doesn't work on the "thread" module: import thread
thread.__file__

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

Mar 9 '06 #1
3 3016
On Thu, Mar 09, 2006 at 02:04:45PM -0800, mh wrote:
So on most modules I import, I can access the .__file__ attribute to
find the implementation. ie:
import time
time.__file__ '/data1/virtualpython/lib/python2.3/lib-dynload/timemodule.so' import socket
socket.__file__ '/data1/virtualpython/lib/python2.3/socket.pyc'

This doesn't work on the "thread" module: import thread
thread.__file__ 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'] <module 'thread' (built-in)> thread <module 'thread' (built-in)> ^D

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
Mar 9 '06 #2
"mh" wrote:
So on most modules I import, I can access the .__file__ attribute to
find the implementation. ie:
import time
time.__file__ '/data1/virtualpython/lib/python2.3/lib-dynload/timemodule.so' import socket
socket.__file__ '/data1/virtualpython/lib/python2.3/socket.pyc'

This doesn't work on the "thread" module: import thread
thread.__file__ 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).

import sys
"thread" in sys.builtin_module_names

True

</F>

Mar 9 '06 #3
On Thu, 09 Mar 2006 17:25:20 -0500, Jack Diederich wrote:
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?
--
Steven.

Mar 11 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Stian Søiland | last post: by
reply views Thread by Simon Dahlbacka | last post: by
2 posts views Thread by unexpected | last post: by
2 posts views Thread by dwelch91 | last post: by
12 posts views Thread by Alan Isaac | last post: by
1 post views Thread by John Boy | last post: by
5 posts views Thread by Gruik | last post: by
5 posts views Thread by Stef Mientki | last post: by
reply views Thread by Gary Herron | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.