Python Identify File Path to Module -
the regular os.path.dirname(__file__)
doesn't work in special setting i'm in. hope not having influence, it's jython 2.7.
text_dir = os.path.dirname(__file__) nameerror: global name '__file__' not defined
if call os.path.dirname(__file__)
inside function works fine.
version 1 (works)
bar.py
import os def bar(): location = os.path.dirname(__file__) return location
version 2 (doesn't work, see above nameerror)
extension.py
import os some_tool import extensions class extended(extensions): def foo(): location = os.path.dirname(__file__)
any idea why? related jython? or because inside class
? or because inherting something?
current workaround
extension.py
import bar some_tool import extensions class extended(extensions): def foo(): location = bar.bar()
the answer below revision 1 of question
it worked me:
$ pwd /tmp $ cat test.py import os; print(os.path.dirname(os.path.realpath(__file__))) $ python test.py /tmp
'__file__'
works me well.
Comments
Post a Comment