Reread Setting.py while the program is running.
-
Reread Setting.py while the program is running.
How can I reload a setting file which I read in by Import Setting at the beginning of the program without leaving the main.py or starting a reset?Problem: I have a setting file that I can update online. However, the new data is not taken over in the variables, but only when I reboot.
How can I do it without restarting.
I am using a While True loop in the main.py.Translated with www.DeepL.com/Translator
-
@Wolli01 I use this little function:
# # reload module: # def reload(mod): import sys mod_name = mod.__name__ del sys.modules[mod_name] return __import__(mod_name)You would call it with:
reload(Setting) -
@robert-hh Thank You
-
@robert-hh Wie rufe ich das auf?
-
@Wolli01
Preload:
from reload import *
then:
reload(Setting)Instead of this function, you can also simply use that sequence directly:
import sys del sys.modules['Setting'] import SettingYou have to take care, in which namespace you are calling it.
-
@robert-hh
import sys
del sys.modules('settings')
time.sleep(1)
import settingsFile "main.py", line 290, in <module>
SyntaxError: can't delete expression -
@Wolli01 Yes. Obviously it is:
del sys.modules['settings']
since sys.modules is a dictionary. This del does not delete the old module, but only allows to reload it.
-
@robert-hh
That's how it works perfectly!
Thank you very much.import sys del sys.modules['settings'] time.sleep(1) import settings
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login