Background of
strong> h5>
- a function needs to be run by dynamically importing the corresponding configuration file according to the configuration of different projects.
solution strong> h5>
- file structure
a #文件夹
│a.py
│__init__.py
b #文件夹
│b.py
│__init__.py
├─c#文件夹
│c.py
│__init__.py
# c.py 中内容
args = {'a':1}
class C:
def c(self):
pass
Purpose of the
-
to a module import c.p y objects in the p> li>
-
solution p> li> ul>
a.py
import importlib
params = importlib.import_module('b.c.c') #绝对导入
params_ = importlib.import_module('.c.c',package='b') #相对导入
# 对象中取出需要的对象
params.args #取出变量
params.C #取出class C
params.C.c #取出class C 中的c 方法
import_module
- file structure
a #文件夹
│a.py
│__init__.py
b #文件夹
│b.py
│__init__.py
├─c#文件夹
│c.py
│__init__.py
# c.py 中内容
args = {'a':1}
class C:
def c(self):
pass
Purpose of the
-
to a module import c.p y objects in the p> li>
-
solution p> li> ul>
a.py
import importlib params = importlib.import_module('b.c.c') #绝对导入 params_ = importlib.import_module('.c.c',package='b') #相对导入 # 对象中取出需要的对象 params.args #取出变量 params.C #取出class C params.C.c #取出class C 中的c 方法
import_module
Read More:
- Attributeerror: ‘module’ object has no attribute ‘handlers’ — Python sub module import problem
- Python import GDAL failed: DLL load failed. The specified module cannot be found.
- When react dynamically prunes components by operating arrays, the state of the remaining components is not preserved. Solution to the problem (method of dynamically setting unique key value)
- Python FileNotFoundError: [Errno 2] No such file or directory: ‘objects/epsilon.pkl
- Module build failed Error Plugin/Preset files are not allowed to export objects, only functions (How to Fix)
- How to Fix gdb error: Failed to import the site module,No module named ‘_sysconfigdata_m’
- Failed to import module __PyInstaller_hooks_0_IPython required by hook for module
- How to import Python from relative path
- Linux dynamically loads kernel modules
- Elasticsearch in Spring uses Spel to dynamically create Index of Documet class
- ImportError: cannot import name ‘SummaryWriter‘ from partially initialized module ‘torch.utils.tenso
- Import sys module
- Solution of OpenCV library import error in Python 3
- From in Python__ future__ The role of import *
- Python scapy module installation and dependency module
- Tensorflow import error: DLL load failed: the specified module could not be found
- The mapboxsdk imports the higher version unity2020 and 2021 and reports an error arbackgroundrenderer
- Python error: typeerror: ‘module’ object is not callable
- uin-app dynamically set the title
- Problem solving module ‘ tensorflow.compat . V2 ‘has no attribute’ contrib ‘and importerror cannot import name’ auto ‘