python错误记录【1】

版权声明:微信 kobesdu https://blog.csdn.net/kobesdu/article/details/82052150

1、SyntaxError: non-default argument follows default argument错误

这种错误原因是将没有默认值的参数在定义时放在了有默认值的参数的后面

 

2IndentationError: expected an indented block

说明此处需要缩进,你只要在出现错误的那一行,按空格或Tab(但不能混用)键缩进就行。

 

3IndentationError: unexpected indent

python是一种对缩进非常敏感的语言  去掉该行前面的缩进

 

4issing 2 required positional arguments: 'animal_

表示函数的实参数目不匹配

 

5TypeError: build_profile() takes 2 positional arguments but 4 were given

函数实参个数与形参不符

 

6AttributeError: 'dict' object has no attribute 'item'

发现是由于使用字典的时候把user_info.items()错写为user_info.item()

 

7No module named 'pizza.py'; 'pizza' is not a package

 Python导入模块名的时候,并不是导入文件名,而是模块名

 

8module 'pizza' has no attribute 'make_pizza'

发现被导入的模块,需要先compile一下,才能被导入,否则报错

 

9SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xb8 in position 0: invalid start byte

带有中文的代码,会出现错误。

 

10File "dog.py", line 2

SyntaxError: Non-UTF-8 code starting with '\xb4' in file dog.py on line 2,

o encoding declared; see http://python.org/dev/peps/pep-0263/ for details

导致出错的根源就是编码问题

首行增加,可解决问题。

 

# coding=gbk

11SyntaxError: invalid syntax

意思就是“语法错误:不正确的语法”。

 

12TypeError: Dog() takes no arguments

出错原因是,在python中构造函数书写格式是__init__,而不是_init_,即在init两侧都是双下划线,不是单下划线。

应当是双下划线

 

13AttributeError: 'Dog' object has no attribute 'name'

字典缺少属性'name'

 

14NameError: name 'makeBuild' is not defined

未定义名称“MaxBug

 

15

猜你喜欢

转载自blog.csdn.net/kobesdu/article/details/82052150
今日推荐