Hi,
I’d like to import importlib… but
ModuleNotFoundError: No module named 'importlib'
What can I do about it?
Why I need it? → reload import of global variable
Hi,
I’d like to import importlib… but
ModuleNotFoundError: No module named 'importlib'
What can I do about it?
Why I need it? → reload import of global variable
importlib
is available for import on the server side, it is not available on the client side.
I don’t think you will get it any time soon (but I might be wrong) because the Python interpreter on the client side is not a full fledged Python interpreter, it’s Skulpt and it has some limitations.
Here you can find more details.
Thank you very much for your prompt reply.
There’s an implementation of importlib.import_module
on the development branch of Anvil Extras
It will be in the next release.
The really bad hacky workaround to what you want to do until it is available is:
from sys import modules
del(modules['global_variable_that_needs_reimport'])
import global_variable_that_needs_reimport
This has a big caveat of ymmv in front of it. Without knowing what you are doing this can be a bad idea.
Yup. If other parts of your code retain references to that module, or objects inside that module, then Python will retain those referenced objects, in order to keep the references themselves valid.
I’ve heard of weak references, which might be a partial solution…