<分区> 分区>
我正在编写一个程序,它使用 os.path.abspath(os.path.dirname(__file__))) 来定位它的配置文件,当我在纯 Python,但是一旦我使用 py2exe 将它编译为 .exe,我就会收到此错误:
Traceback (most recent call last):
File (main.py, line 17, in <module>
NameError: name '__file__' is not defined
确切地说,第 17 行是:
if os.path.isfile("%s/config.cfg" % os.path.abspath(os.path.dirname(__file__))):
为什么会发生这种情况,我该如何克服这个问题?
提前致谢! :)
