python编程常见错误笔记

来源:互联网 发布:辣妈淘美美 淘宝达人 编辑:程序博客网 时间:2024/06/06 09:30

1:python中SyntaxError:Non-ASCII解决方法:

[python] view plain copy
  1. File "F:\progrem\luna\DeepLearningBasicsMachineLearned\DecisionTree\AllElectronics_1.py", line 1  
  2. SyntaxError: Non-ASCII character '\xe5' in file F:\progrem\luna\DeepLearningBasicsMachineLearned\DecisionTree\AllElectronics_1.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263for details  

解决这个错误只需要在Python头部加上:

[python] view plain copy
  1. #-*- coding:utf-8 -*-  

2:python中IndentationError: expected an indented block解决方法:

出现这个错误,你根据错误提示行查看你的代码是否缩进了,一般是因为语句没有缩进引起的。

3:python中socket.error:[Errno 9] Bad file descriptor解决方法:

[python] view plain copy
  1. waiting for connection...  
  2. ....connected from: ('127.0.0.1'58022)  
  3. Traceback (most recent call last):  
  4.   File "tsTserv.py", line 20in <module>  
  5.     data = tcpCliSock.recv(BUFSIZ)  
  6.   File "/usr/lib/python2.7/socket.py", line 174in _dummy  
  7.     raise error(EBADF, 'Bad file descriptor')  
  8. socket.error: [Errno 9] Bad file descriptor  
出现这个错误一般是服务器还需要接受data而客户端的socket连接已经关闭了,这时你需要查看你客户端socket关闭连接的位置是否正确