#๐Ÿ”’ importlib.reload() does not work

17 messages ยท Page 1 of 1 (latest)

quick rapids
#
import config
import sys
import importlib

def menu():
    try:
        print(colors.BOLD + colors.CYAN + "Welcome to Houdini\n" + colors.RESET)
        while True:
            display_menu()
            choice = get_user_choice()
            importlib.reload(config)
            print(KERNEL_VERSION)
            if choice in menu_options:
                menu_options[choice]()
            else:
                print("Invalid choice. Please try again.")

umbral roostBOT
#

@quick rapids

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

quick rapids
#

when I change config.py, and then do importlib.reload(config), it does not change the KERNEL_VERSION

#
KERNEL_VERSION = "5.18.5"
tawdry dirge
#

Where is KERNEL_VERSION defined?

#

In the second file

quick rapids
#

second file is just that

#

nothing else

#

it's a global variable

#

so line 1

tawdry dirge
#

If you're doing something like this:

KERNEL_VERSION = config.KERNEL_VERSION

Updating the module will not reassign the variable in this module.

quick rapids
#

what

tawdry dirge
#

You shouldn't be reloading the module anyway. Make a function that fetches the version, and call that when you need to know the version number.

quick rapids
#

but i want to able to change the KERNEL_VERSION value and using that without terminating my program

umbral roostBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.