>>> names=['jill','jack']
>>> isinstance(names,list)
Traceback (most recent call last):
File "<pyshell#291>", line 1, in <module>
isinstance(names,list)
TypeError: isinstance() arg 2 must be a type or tuple of types
>>>
我在这里错过了什么吗?
>>> names=['jill','jack']
>>> isinstance(names,list)
Traceback (most recent call last):
File "<pyshell#291>", line 1, in <module>
isinstance(names,list)
TypeError: isinstance() arg 2 must be a type or tuple of types
>>>
我在这里错过了什么吗?
list
您已经通过分配给同名的局部变量来踩踏。不要那样做。
应用这个:
if isinstance(names, type(list)):
如果您不小心弄乱了模型中的外键字段语法,也会发生这种情况。编写外键字段时,您可以:
ModelName
或者:
'app_name.ModelName'
但你不能拥有:
'ModelName'
学到了一个艰难的方式。
但这适用于 Python (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32:</p>
>>> names=['jill', 'jack']
>>> isinstance(names, list)
True