Search code examples
pythonpyinstaller

How to update the variable list in the config file dynamically in to python exe file


I have a python file that converted into exe using pyinstaller but i need to get the data from another file which is to be updated and without another pyinstaller execution it needed to be worked like getting a data from the config file to exe

from configfile import variables

variables that is loaded from the configfile.py file but after converting into exe i cant able to update configfile.py variables

any suggestion will be welcomed


Solution

  • function from the python config file updated and loaded dynamically outside the environment of 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()