[Python-Dev] __file__

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Feb 28 02:25:15 CET 2010


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.

-- 
Greg


More information about the Python-Dev mailing list