在下面的代碼的方法如何使Unicode數據callable.The錯誤,我得到的是//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')
你嘗試調用其名*通過了'i.header'變量引用的方法? – shx2
請參閱已更新的問題 – Rajeev
當您打電話時,您期望它做什麼? –