# somemodule.py
def func_a():
print('hello a')
def func_b():
print('hello b')
# yourcode.py
import inspect
import importlib
def pepimports(the_module_name):
mymodule = importlib.import_module(the_module_name)
myfuncs = inspect.getmembers(f, inspect.isfunction)
for f in myfuncs:
setattr(mymodule, _pep8ify(f[1].__name__) , f[1])
return mymodule
mymodule = pepimports('some_module_name')
# you can now call the functions from mymodule
# (the original names still exist, so watch out for clashes)
mymodule.pepified_function()
可以使用上下文管理器自动识别导入模块中的符号,例如:
示例:
代码:
^{pr2}$测试代码:
在时髦.py
结果:
我想这样的事情能达到你想要的效果:
它有点老套,但我已经尝试过了(Python3.5),它似乎可以工作(至少在一个小例子上)。在
相关问题 更多 >
编程相关推荐