Issue1472

classification
Title: __file__ giving $py.class on second import
Type: behaviour Severity: normal
Components: Core Versions: 2.5.1
Milestone:
process
Status: closed Resolution: invalid
Dependencies: Superseder:
Assigned To: Nosy List: gdoutch, pjenvey
Priority: Keywords:

Created on 2009-09-17.10:26:49 by gdoutch, last changed 2009-09-17.18:37:46 by pjenvey.

Messages
msg5182 (view) Author: Gareth Doutch (gdoutch) Date: 2009-09-17.10:26:48
I am using Jython 2.5.1 rc 2 on java1.6.0_11 on Win XP.

If I use a very simple bit of code in a file called getfile.py:

print __file__


The following command trace demonstrates its behaviour:

C:\jython2.5.1rc2>jython getfile.py
getfile.py

C:\jython2.5.1rc2>jython getfile.py
getfile.py

C:\jython2.5.1rc2>jython
Jython 2.5.1rc1 (Release_2_5_1rc1:6736:6741, Sep 1 2009, 10:37:37)
[Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_11
Type "help", "copyright", "credits" or "license" for more information.
>>> import getfile
getfile.py
>>> →

C:\jython2.5.1rc2>jython
Jython 2.5.1rc1 (Release_2_5_1rc1:6736:6741, Sep 1 2009, 10:37:37)
[Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_11
Type "help", "copyright", "credits" or "license" for more information.
>>> import getfile
getfile$py.class
>>> →
msg5183 (view) Author: Gareth Doutch (gdoutch) Date: 2009-09-17.10:36:32
OK, so this is default behavior?

I see the same happens in python:

C:\Python25>python getfile.py
getfile.py

C:\Python25>python getfile.py
getfile.py

C:\Python25>python
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import getfile
getfile.py
>>> ^Z


C:\Python25>python
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import getfile
getfile.pyc
>>>


What would be the workaround if the name of the compiled file is of no
use to you, only the original script?
msg5185 (view) Author: Philip Jenvey (pjenvey) Date: 2009-09-17.18:37:45
This is the intended behavior as you've found with CPython. You always 
need to handle the extension when you're trying to determine the 
original .py script from __file__, e.g. see doctest's handling of it:

http://fisheye3.atlassian.com/browse/jython/trunk/jython/Lib/doctest.py?
r=5206#l967
History
Date User Action Args
2009-09-17 18:37:46pjenveysetstatus: open -> closed
resolution: invalid
messages: + msg5185
nosy: + pjenvey
2009-09-17 10:36:32gdoutchsetmessages: + msg5183
2009-09-17 10:26:49gdoutchcreate