473,405 Members | 2,154 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,405 software developers and data experts.

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/list.../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
Aug 29 '08 #1
2 3632
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
Aug 29 '08 #2
On Aug 29, 6:11*pm, "Diez B. Roggisch" <de...@nospam.web.dewrote:
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.
Aug 30 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Andreas Neudecker | last post by:
Hi. I know you can read the filename of a program as sys.argv. But what about modules? Is there a similar way to find out the file name of a module (called by some other module or program) from...
2
by: Reid Priedhorsky | last post by:
Dear group, I'd have a class defined in one module, which descends from another class defined in a different module. I'd like the superclass to be able to access objects defined in the first...
12
by: Steven Bethard | last post by:
Ok, so I have a module that is basically a Python wrapper around a big lookup table stored in a text file. The module needs to provide a few functions:: get_stem(word, pos, default=None)...
30
by: Franck PEREZ | last post by:
Hello, I'm developing a small XML marshaller and I'm facing an annoying issue. Here's some sample code: ########### My test application ############ class Foo(object): #The class I'd like to...
2
by: David Bear | last post by:
I'm confused about how to use the email module in python 2.4.x I'm using python packaged with suse 9.3. From the module documetation at http://docs.python.org/lib/node597.html I found the...
3
by: Jugdish | last post by:
Why doesn't the following work? $HOME/pkg/__init__.py $HOME/pkg/subpkg/__init__.py $HOME/pkg/subpkg/a.py $HOME/pkg/subpkg/b.py # empty import a
5
by: dg.google.groups | last post by:
Hi all, Is there any standard way to tell if the user is running from a module or from an interactive shell like IDLE or IPython? The best I've come up with so far is for a function to look at...
3
by: mrstephengross | last post by:
Hi all. I've got a python file called 'foo' (no extension). I want to be able to load it as a module, like so: m = __import__('foo') However, the interpreter tells me "No module named foo". If...
0
by: Jean-Paul Calderone | last post by:
On 29 Aug 2008 15:21:53 GMT, Steven D'Aprano <steve@remove-this-cybersource.com.auwrote: This seems particularly pointless. If __file__ were changed to make it easier to handle by making the...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.