[Python-Dev] __file__

Glenn Linderman v+python at g.nevcal.com
Sun Feb 28 05:50:02 CET 2010


On approximately 2/27/2010 5:25 PM, came the following characters from 
the keyboard of Greg Ewing:
> Glenn Linderman wrote:
>>> What I did was:
>>>> python -m test
>> ren test.pyc foo.py
>> foo.py
>>>> and it worked.
>> Source files mentioned on the command line aren't required to
> have a .py extension. I think what's happening is that the
> interpreter ignores the filename altogether in that case and
> examines the contents of the file to figure out what it is,
> in order to support running .pyc files from the command line.

Thanks for the explanation. Brett mentioned something like runpy vs 
import using different techniques. Which is OK, I guess, but if the 
command line/runpy can do it, the importer could do it. Just a matter 
of desire and coding. Whether it is worth pursuing further depends on 
people's perceptions of "kookiness" vs. functional and performance 
considerations.
-- 
Glenn -- http://nevcal.com/
===========================
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /