一、python 记录报错
1、can't assign to fuunction call
list(i+1) = list(i) //python中圆括号()表示函数调用,方括号[]表示列表值的引用,这里需使用[]
运行:
>>>can't assign to fuunction call
2、object is not subscriptable
list[i].extend(["a","b","c"]) //错误的原因就是把不具有下标操作的对象用成了对象[i]
运行:
>>>object is not subscriptable
3、'type' object does not support item assignment,
此类型是不可变对象,不能用下标赋值的方式去改变。
list[i] =[]
运行:
>>>'type' object does not support item assignment
4、'invalid character in identifier'
,
可能不是你没有定义这个变量,而是它前面或者后面的标点用成了中文的!!!
5、NameError: name 'each_line' is not defined,
f = open('D:\\大学.txt')
if each_line in f:
print()
注意!each_line是在f.readlines()时,在for循环里面用的,只能用作 for each_line in f:
而不能用在if语句里面!
6、字符串分片时,提示ValueError: not enough values to unpack (expected 2, got 1)
f = open('D:\\新建文本文档.txt')
for each_line in f:
(role,line_spoken) = each_line.split(':',1)
这里只需要注意,你的文档里面是用中文写的,标点也自然是中文的,而如果你用英文的冒号去索引切片,自然就无法切片
7、SyntaxError: unexpected EOF while parsing
括号少了或者输入了中文符号