如何将配置文件中的变量列表动态更新到 python exe 文件
How to update the variable list in the config file dynamically in to python exe file
我有一个 python 使用 pyinstaller 转换成 exe 的文件
但我需要从另一个要更新的文件中获取数据,并且在没有另一个 pyinstaller 执行的情况下,它需要像从配置文件中获取数据到 exe
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()
我有一个 python 使用 pyinstaller 转换成 exe 的文件 但我需要从另一个要更新的文件中获取数据,并且在没有另一个 pyinstaller 执行的情况下,它需要像从配置文件中获取数据到 exe
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()