![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
初学python那些错误
Pika_T
这个作者很懒,什么都没留下…
展开
-
列表取片操作易错点(list indices must be integers or slices, not tuple原因及解决方法)
list indices must be integers or slices, not tuple原因及解决方法场景:在对列表进行取数据时报错,报错代码:TypeError: list indices must be integers or slices, not tuple翻译:列表索引必须是整数(取某一个数据,例如:data[0])或者片(取某一片数据,例如data[0:2]),不能是元组(tuple是元组的意思)原因:当我们用data=[]并通过append等方法创建数据时,创建的d原创 2021-03-29 14:39:29 · 186743 阅读 · 8 评论 -
object is not subscriptable
object is not subscriptable的问题所在TypeError: 'builtin_function_or_method' object is not subscriptable问题翻译过来就是:代码中有函数或方法对象是不可有下标的(但写成了有下标的)错误的原代码如下:s=f.readlines()for row in s: oneRow=row.split('\t') data.append[list(oneRow)]错误点便是append是一种方法/函原创 2021-03-29 13:44:42 · 27835 阅读 · 0 评论 -
python读取文件错误解决办法
‘gbk’ codec can’t decode byte 0xa9 in position 14: illegal multibyte sequence的解决办法python在读取txt文件时,全是数字的时候没有这个错误,但当txt文件里面有中文,报错了。原因是txt文件编码格式若为utf-8的话,用gbk编码格式去编辑便不能decode(解码)解决办法便是在读取文件时候将txt文件以指定编码格式打开,而不是默认的gbk编码,比如若txt文件是utf-8编码格式的,则可以使用如下代码:f=open原创 2021-03-29 12:42:23 · 1784 阅读 · 3 评论