Title: __file__ not set properly?
Type: Severity: normal
Components: Core Versions:
Status: closed Resolution: invalid
Dependencies: Superseder:
Assigned To: Nosy List: Christof, thobes
Priority: Keywords:

Created on 2009-06-16.19:49:18 by Christof, last changed 2009-07-21.10:00:27 by thobes.

msg4816 (view) Author: Christof (Christof) Date: 2009-06-16.19:49:18
I try to put a subdirectory relative to a given script on sys.path and
therefore need os.path.dirname(__file__). Filename e.g. is and
it is on c:\temp:

import os
print __file__, os.path.dirname(__file__)

c:\temp\ c:\temp

Jython 2.5final:

So only the filename and therefor no possibility to add e.g. a libs dir
relative to this script to sys.path.

Guess this is known but could not find any hint to this problem and
possible workaround or if there is hope for Jython 2.5.1?

msg4928 (view) Author: Tobias Ivarsson (thobes) Date: 2009-07-20.10:12:51
As far as I can tell Jython and CPython behave in the same way here. But
this could be some sort of Winblows issue.

CPython regularly assigns relative paths to __file__ as well. The proper
use in this case would be:

  scriptdir = os.path.dirname(os.path.abspath(__file__))
msg4933 (view) Author: Christof (Christof) Date: 2009-07-20.18:13:43
oops, sorry. I think I used a wrong script and your example (which I
normally use too ;) does of course work in Python and Jython (2.5.0).
    import os
    print os.path.dirname(os.path.abspath(__file__)), __file__



Jython 2.5.0 (Release_2_5_0:6476, Jun 16 2009, 13:33:26)
[Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_07
Type "help", "copyright", "credits" or "license" for more information.

Should be closed of course.
Date User Action Args
2009-07-21 10:00:27thobessetstatus: pending -> closed
resolution: works for me -> invalid
2009-07-20 18:13:44Christofsetmessages: + msg4933
2009-07-20 10:12:52thobessetstatus: open -> pending
resolution: works for me
messages: + msg4928
nosy: + thobes
2009-06-16 19:49:18Christofcreate