如何将配置文件中的变量列表动态更新为Python EXE文件



我有一个使用pyinstaller转换为exe的python文件但是我需要从要更新的另一个文件中获取数据,并且如果没有其他Pyinstaller执行,则需要工作,就像从配置文件中获取数据一样

from configfile import variables

variables从configfile.py文件加载,但是转换为exe后,我无法更新configfile.py变量

任何建议都将受到欢迎

功能从python配置文件更新和在Exe

的环境之外动态加载和加载
import os
extDataDir = os.getcwd()
ext_config = os.path.join(extDataDir, '', 'configfile.py')

def importCode(code,name,add_to_sys_modules=0):
    import sys,imp
    module = imp.new_module(name)
    exec(code,module.__dict__)
    if add_to_sys_modules:
        sys.modules[name] = module
    return module
configfile_rd = open(ext_config, "r")
configfile_code = configfile_rd.read()
configfile = importCode(configfile_code,"configfile") #dynamically readed the config file from exe and execute the python file configfile.py and working as well as import configfile
constant = configfile.variables()

最新更新