可能重复:
os.path.dirname(__file__) returns empty蟒蛇2.7 os.path.dirname(__ FILE__)返回在Debian空字符串(Win7上正常工作)
这里是我的一段代码:
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
完全工作在Windows,但返回Debian的空字符串。任何想法可能是什么问题?
我使用Python 2.7.3,6.0.5的Debian
你有没有想过加入打印语句来检查您输入与条件子句的分支? – mgilson
http://stackoverflow.com/questions/7783308/os-path-dirname-file-returns-empty –
你在根目录下运行呢? – hughdbrown