How to make an import python?

Import a module from a string. The problem is that the module name can be the same as with a built-in module and then imported built-in. This code solves the problem:
from importlib import util
spec = util.spec_from_file_location("", "/path/to/")
foo = util.module_from_spec(spec)

Is there any easier way to do this?
March 12th 20 at 08:11
1 answer
March 12th 20 at 08:13
Yes, a little tense with the names of the modules to avoid intersections
Or scopes, to put the same name module in a package and import as

import package

And refer to it as

Or you can import a module from a package, giving it a different name:

from package import module as my_module

Benefit packages in Python -- it's easy: make a folder, create an empty . Well, to add a module to the package, moving it to the folder you created. Importantly, the folder lay next to run file, otherwise you'll have an additional path for the import to register. - savanna_Kirlin9 commented on March 12th 20 at 08:16

Find more questions by tags Python