Message1217

Author pekka.klarck
Recipients
Date 2006-08-29.11:41:57
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
It seems that __file__ is not available when running
file as a script even though it is there when you
import it as a module.

There's also small inconsistency between Jython and
CPython because in Jython the file is returned in
absolute format but in CPython it is relative to the
directory where Python is run. This may in some cases
cause problem when you run code developed for CPython
in Jython -- when developing code for both you realize
that you have to use os.path.abspath or
os.path.basename depending what you want.


Example:

$ echo 'print __file__' > test.py

$ jython test.py 
Traceback (innermost last):
  File "test.py", line 1, in ?
NameError: __file__

$ jython
Jython 2.2a1 on java1.5.0_04 (JIT: null)
Type "copyright", "credits" or "license" for more
information.
>>> import test
c:\path\test.py
>>> 

$ python test.py 
test.py

$ python
Python 2.4.3 (#1, May 18 2006, 07:40:45) 
[GCC 3.3.3 (cygwin special)] on cygwin
Type "help", "copyright", "credits" or "license" for
more information.
>>> import test
test.py
>>> 

History
Date User Action Args
2008-02-20 17:17:32adminlinkissue1548501 messages
2008-02-20 17:17:32admincreate