"weird" behavior of __file__ attribute

cherzog ccf.herzog at gmx.net
Fri Sep 7 14:50:15 CEST 2001

Hello All,
The __file__ attribute of a module behaves in a way I do not understand:
I have the following example on Windows with Python 2.1: I got two files in
first: C:\mytest.py
second: C:\mytestA.py

mytest.py is:
#----------start of file------
import os
import mytestA
print "cwd: ", os.getcwd()
print "mytestA.__file__: ", mytestA.__file__
#----------end of file

while mytestA.py says simply hello:

#----------start of file------
print "hello"
#----------end of file

If I type:
I get:
cwd:  C:\
mytestA.__file__:  C:\mytestA.py

But if I type:
C:\>C:\programme\python21\python mytest.py
I get:
cwd:  C:\
mytestA.__file__:  mytestA.pyc

This is not what I wanted because I hoped to find out the exact path of
module mytestA.py no matter  how I call mytest.py.
Please, can someone help me?
Thank you

More information about the Python-list mailing list