python 错误集

来源:互联网 发布:yy淘宝兼职刷信誉 编辑:程序博客网 时间:2024/06/06 16:56

TypeError: ‘str’ object is not callable

原因是str()方法被调用时,发现代码中定义过一个叫str的变量,覆盖了str方法。

# str = 'Hello World!'# print str,type(str)

解决方法:将变量注释或rename

IOError: [Errno 2] No such file or directory: ‘aaa.txt’

file = open('aaa.txt')

原因路径错误,找不到文件

ImportError: No module named A

import A

导入模块错误,没有该模块

IndexError: list index out of range

list1 = [1,2,3]print list1[3]

索引错误,list索引超出范围

KeyError: ‘height’

KeyError:字典中不存在的键

dict1 = {'name':'ivy','age':20,'gender':'female'}print dict1['height']

NameError: name ‘a’ is not defined

NameError:访问没有定义的变量

print a

IndentationError: expected an indented block

IndentationError:缩进错误

if 1==1:print 'aaa'

SyntaxError: invalid syntax

SyntaxError:语法错误

list2 = [1,2,3,4】

TypeError: unsupported operand type(s) for +: ‘int’ and ‘str’

TypeError:不同类型间的无效操作

print 1+'1'

int和字符之间拼接不能用+号

ZeroDivisionError: integer division or modulo by zero

ZeroDivisionError:除数为0

 print 5/0
0 0
原创粉丝点击