我似乎找不到模块绑定的实际名称存储在哪里。 例如:
import re as my_re
print my_re.__name__ # Output is "re," not "my_re"
我希望能够获取导入模块时使用的名称,而不是实际模块的名称。
我的使用情况是我有一个函数,它以函数对象作为参数,并需要确定绑定到哪个名称。以下是更详细的示例:
import module as my_module
def my_func(in_func):
print in_func.__bound-name__ # Or something to this effect
my_func(my_module.function1) # Should print "my_module.function1"