From: Kevin A. M. <re...@bu...> - 2008-09-23 15:05:42
|
New submission from Kevin A. Mitchell <ka...@da...>: It seems that the __file__ module attribute reflects the original source, not the location the module was loaded from as would be expected. A test case can be simply made from two files: imported.py and testimport.py imported.py: import os base = os.path.dirname(__file__) top = os.path.abspath(base) up = os.path.abspath(os.path.join(base, '..')) print __file__, base, top, up testimport.py: from imported import * Running gives the same results in Jython and CPython: $ jython testimport.py /Users/kam/src/importtest/imported.py /Users/kam/src/importtest /Users/kam/src/importtest /Users/kam/src $ python testimport.py /Users/kam/src/importtest/imported.py /Users/kam/src/importtest /Users/kam/src/importtest /Users/kam/src ...but if the directory tree is copied or renamed: $ cd .. $ rsync -avP importtest/ it/ $ cd it $ python testimport.py /Users/kam/src/it/imported.pyc /Users/kam/src/it /Users/kam/src/it /Users/kam/src $ jython testimport.py /Users/kam/src/importtest/imported.py /Users/kam/src/importtest /Users/kam/src/importtest /Users/kam/src But if the class file is removed: $ rm imported\$py.class $ jython testimport.py /Users/kam/src/it /Users/kam/src/it /Users/kam/src ...the correct value is now calculated. http://docs.python.org/ref/types.html says "__file__ is the pathname of the file from which the module was loaded, if it was loaded from a file". Apparently, Jython is storing the name of the original Python file and using that. It would be expected that __file__ would contain the name of the $py.class file it was loaded from. ---------- components: Core messages: 3614 nosy: kam severity: normal status: open title: __file__ reflects original source location, not the pathname of the $py.class file versions: 2.5alpha3 _______________________________________ Jython tracker <re...@bu...> <http://bugs.jython.org/issue1138> _______________________________________ |