出于某种原因,我无法让 isinstance() 在 Python 2.7.2 上工作
def print_lol(the_list, indent=False, level=0):
for item in the_list:
if isinstance(item, list):
print_lol(item, indent, level+1)
else:
print(item)
当我编译并运行它时:
>>> list = ["q", "w", ["D", ["E", "I"]]]
>>> print_lol(list)
我收到错误消息:
if isinstance(item, list):
TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types
我错过了什么?