一些报错
SyntaxError: Non-ASCII character '\xef' in file server.py on line xx, but no encoding declared
解决方案:
在第一行加入#coding:utf-8
注意:一定是在第一行加,python2.7实测可以。
IndentationError:expected an indented block
说明此处需要缩进,你只要在出现错误的那一行,按空格或Tab(但不能混用)键缩进就行。
IndentationError: unindent does not match any outer indentation level
1.对于此错误,最常见的原因是,的确没有对齐。
2.前面的注释的内容影响后面的语句的语法了
3.把当前python脚本的所有字符都显示出来看看有没有啥特殊的字符。新的Python语法,是不支持的代码对齐中,混用TAB和空格的。
IndexError: list index out of range
第1种可能情况
list[index]index超出范围,也就是常说的数组越界
第2种可能情况
list是一个空的 没有一个元素
进行list[0]就会出现该错误,这在爬虫问题中很常见,比如有个列表爬去下来为空,统一处理就会报错
syntax error invalid syntax
忘记在 if , elif , else , for , while , class ,def 声明末尾添加 :
多标点符号,拼写错误
尝试使用Python关键字作为变量名,Python3的关键字有:and, as, assert, break, class, continue, def, del, elif, else, except, False, finally, for, from, global, if, import, in, is, lambda, None, nonlocal, not, or, pass, raise, return, True, try, while, with, yield
错误的使用缩进量。(导致“IndentationError:unexpected indent”、“IndentationError:unindent does not match any outer indetation level”以及“IndentationError:expected an indented block”)