我有一个使用ConfigParser.ConfigParser()
访问配置文件的Python应用程序。我使用py2exe
创建了Python应用程序的Windows服务。我遇到的问题是,如果将服务放在windows/system32
文件夹中,该服务只能找到配置文件。我想将配置文件放在安装服务的同一文件夹中。例如,使用py2exe
后,我有以下文件夹:
c:/temp/dist/winservice.exe
c:/temp/dist/configfile.cfg
然后我这样做:
winservice.exe install
但该服务不会在路径configfile.cfg
中查找c:/temp/dist/
,而是在路径中查找:c:/windows/system32/
有没有办法改变它?
谢谢!
答案 0 :(得分:0)
您可以使用Inspect模块获取创建此代码对象的文件的名称。 因此,要获取您将使用的文件的路径:inspect.currentframe()。f_code.co_filename
因此,要获取winservice.exe所在的目录名称:
dirPath = os.path.dirname(inspect.currentframe()。f_code.co_filename)
希望有所帮助