473,378 Members | 1,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 3202
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Stian Søiland | last post by:
all examples performed with: Python 2.3+ (#2, Aug 10 2003, 11:09:33) on linux2 (2, 3, 0, 'final', 1) This is a recursive import:
0
by: Simon Dahlbacka | last post by:
I recently had a problem caused by path extension (sys.path.extend) so that a module/package got imported twice both as foo.module and module, which caused all sorts of problems. Naturally best...
2
by: unexpected | last post by:
Hey guys, I'm having problems importing a file into my python app. Everytime I try to define the object specified by this file, i.e, test = Test(), It raises an ImportError exception:...
2
by: dwelch91 | last post by:
Hi, c.l.p.'ers- I am having a problem with the import of xml.parsers.expat that has gotten me completely stumped. I have two programs, one a PyQt program and one a command line (text) program...
12
by: Alan Isaac | last post by:
Are relative imports broken in 2.5? Directory ``temp`` contains:: __init__.py test1.py test2.py File contents: __init__.py and test2.py are empty test1.py contains a single line::
1
by: John Boy | last post by:
First post and very much a newbie to Python. Have 2.5 on Linux (GG). I think I have set up PYTHONPATH correctly in that I can import a module apply_bp and it complains about line 20 in apply_bp...
5
by: Gruik | last post by:
Hi people, I'm currently working on python embedding with C++. My goal is that the C++ part handle files writing/reading so that the Python part only works with buffers. I succeeded in buffer...
5
by: Stef Mientki | last post by:
hello, The import statement "import sqlite3" gives the error given below. In simple programs, the import statement (sometimes) succeed, and I can indeed access the database. So I guess there is...
0
by: Gary Herron | last post by:
Dan Yamins wrote: Because loading (and reloading) assigns values to variables (called binding a value in Python), but does not go on a hunt to find variables to *unbind*. Once a variable is...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.