给定带有__init__.py
文件的模块mymodule
,如何从该文件中的另一个函数定义mymodule的函数
__init__.py
代码大纲:
def a():
THISMODULE.__dict__["b"] = lambda: print("this is not weird")
a()
b() # Expect "this is not weird" output
mymodule
是作为anothermodule
的替代品出现的,我想让代码更改简单到用import mymodule as thething
替换import anothermodule as thething
。因为我还没有实现anothermodule
的所有功能,所以我想向用户发送一个关于它的通知,而不是用“未定义”来崩溃
^{} 是导入机制设置的模块属性,其计算结果为当前模块的名称。将其添加到文件的顶部:
你已经拥有的其他东西应该能正常工作
相关问题 更多 >
编程相关推荐