Answer the question
In order to leave comments, you need to log in
How to do import in python?
I import a module from a string. The problem is that the name of a module can be the same as a built-in module, and then the built-in one is imported. This code solves the problem:
from importlib import util
spec = util.spec_from_file_location("module.name", "/path/to/file.py")
foo = util.module_from_spec(spec)
spec.loader.exec_module(foo)
Answer the question
In order to leave comments, you need to log in
Yes, be a little tense with the names of the modules so that there are no intersections
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question