Reputation: 141
i have a configuration file in python that can be changed while the main script is running, so i need to reload it.
i tried the answer in this post: python refresh/reload
import config
from config import *
...
reload(config)
from config import *
it worked until i entered the reload part to a function, so if i do this:
import config
from config import *
def main():
reload(config)
from config import *
i get the warning: 'import *' only allowed in module level, the script is running but the reload isn't working,
i also tried "import config" instead of "from config import *" but i got an exception "UnboundLocalError: local variable 'config' referenced before assignment"
Upvotes: 1
Views: 838
Reputation: 171
I suggest you to store your configuration in a file rather than a module. Please take a look at the ConfigParser
module from Python. From what I've heard, it can handle ini files too.
Upvotes: 1