0

Possible Duplicate:
os.path.dirname(__file__) returns empty

Here's my piece of code:

def GetAppPath():
    application_path = None
    if getattr(sys, 'frozen', False):
        application_path = os.path.dirname(sys.executable)
    elif __file__:
        application_path = os.path.dirname(__file__)
    return application_path

Works perfectly on Windows, but returns empty string on Debian. Any ideas what could be the problem?

I'm using Python 2.7.3, Debian 6.0.5

Community
  • 1
  • 1
Max Gruzin
  • 1,143
  • 1
  • 15
  • 22

2 Answers2

1

Seems like __file__ is not defined or defined incorrectly, works for me on Debian testing, Python 2.7.3rc2

    def GetAppPath(file):
        application_path = os.path.dirname(file)
        return application_path

GetAppPath('/etc/X11/xorg.conf') returns '/etc/X11'

hughdbrown
  • 47,733
  • 20
  • 85
  • 108
insider
  • 1,818
  • 2
  • 17
  • 15
1

Works for me on Ubuntu 12.04/python 2.7:

import os.path

print os.path.dirname(__file__)

Store in /tmp/foo.py and then run it:

$ python /tmp/foo.py 
/tmp
hughdbrown
  • 47,733
  • 20
  • 85
  • 108