Dhr*_*tel 3 python string import arguments
我想允许用户根据他们的字符串输入参数导入一个模块。
IE
$python myprogram.py --import_option xyz.py
Run Code Online (Sandbox Code Playgroud)
在python中,我在解析一个参数后想要这样的东西。
arg = 'xyz.py'
import arg #assuming that the module name xyz.py exists.
Run Code Online (Sandbox Code Playgroud)
>>> a='math'
>>> import importlib
>>> i=importlib.import_module(a)
>>> i.sqrt(4)
2.0
Run Code Online (Sandbox Code Playgroud)