【发布时间】:2013-12-06 22:59:59
【问题描述】:
在以下代码中如何使 unicode 数据可调用。我得到的错误是 //TypeError: 'unicode' object is not callable
def test(test_config):
for i in test_config:
print i.header //prints func1
print type(i.header) // prints unicode
try:
#i.header()//TypeError: 'unicode' object is not callable
func = globals()[i.header]
print func # found it
func()
except AttributeError:
logging.error("Method %s not implemented"%(i.header))
def func1():
print "In func1"
test(u'func1')
【问题讨论】:
-
您是否正在尝试调用其 name 被
i.header变量引用的方法? -
请查看更新后的问题
-
你调用它时希望它做什么?
-
您希望
"print" ('Hello World.')工作吗?如果是,它在 python 中不会这样工作。
标签: python function-call