使用python中常见的错误及处理办法(1)
2017-09-11 22:58
585 查看
(1)invalid literal for int( ) with base 10:'largeDoses'
解决办法:这是因为数据类型不一致,导致出错,在int/str/float转换,其中raw_input接收字符串,input接收整数
(2)‘
4000
^
syntaxError:invalid syntax‘
解决办法:可能是标点符号、括号、双引号等不配对,需要增加或者删除
(3)‘ NameError:name'sorted Dist Indicies' is not defined ’
解决办法:这是因为变量前后不匹配,需要增加或者减少某个字母;有可能是前后大小写不同而引起不能识别
(4)‘dict_keys’ object does't support indexing
解决办法:这是因为python版本不一致,所以对列表的索引出现问题
例:firstsides = mytree.keys( )[0] 应该改为:firstsides = list(mytree.keys( ))[0]
(5)‘write( ) argument must be str, not byes’
解决办法:pickle( ) 是二进制格式,故带'b'标志打开文件‘wb/rb’
(6)同一目录下相互调用函数的做法是
-------先import 文件名
-------再文件名.函数
例:import treeplotter
treeplotter.createplot(lensesTree)
(7)‘date type not understood!’
例:returnMat = zeros(numberoflines, 3)
修改为:returnMat = zeros((numberoflines, 3)),别忘了外面的括号!!!
(8)‘ return arrays must be of ArrayType’
例:shannoEnt -= prob * log(prob,2)
修改为:shannoEnt -= prob * np.math.log(prob,2)
(9)’can't multiply sequence by non-int of type float‘’
解决办法:需要将出错的地方转换数据类型
(10)'itertools cycle' object has no attribute 'next'
原因:编辑版本的原因,出现差错
例:idexer.next( )
修改为:next(idexer)
(11)‘list index out of range’
原因:(1)list[index],index超出范围
(2)list是空列表,进行list[0]就会出错
(12)‘‘int’ object is not iterable’
例:for i in hosts:
修改为:for i in range(hosts):
(13)'unindent does not mach any outer indentation level '
原因:注意缩进,在某行的开头处可能被空格了一下
(14)'could not convert string to float '
原因:(1)可能是文本格式的问题----数据应先在外边的文本.txt编辑后再导入,否则就会引起这种错误的提示
(2)可能在数据分割时出错,将split('\n')改成split(',')
(15)'only length-1 arrays can be converted to python scalars'
原因:不要将列表转换成矩阵形式,
例:math.log(a) ----->np.log(a)
(16)list( ) takes at most 1 argument (2 given)
原因:list 至多1个参数
解决办法:这是因为数据类型不一致,导致出错,在int/str/float转换,其中raw_input接收字符串,input接收整数
(2)‘
4000
^
syntaxError:invalid syntax‘
解决办法:可能是标点符号、括号、双引号等不配对,需要增加或者删除
(3)‘ NameError:name'sorted Dist Indicies' is not defined ’
解决办法:这是因为变量前后不匹配,需要增加或者减少某个字母;有可能是前后大小写不同而引起不能识别
(4)‘dict_keys’ object does't support indexing
解决办法:这是因为python版本不一致,所以对列表的索引出现问题
例:firstsides = mytree.keys( )[0] 应该改为:firstsides = list(mytree.keys( ))[0]
(5)‘write( ) argument must be str, not byes’
解决办法:pickle( ) 是二进制格式,故带'b'标志打开文件‘wb/rb’
(6)同一目录下相互调用函数的做法是
-------先import 文件名
-------再文件名.函数
例:import treeplotter
treeplotter.createplot(lensesTree)
(7)‘date type not understood!’
例:returnMat = zeros(numberoflines, 3)
修改为:returnMat = zeros((numberoflines, 3)),别忘了外面的括号!!!
(8)‘ return arrays must be of ArrayType’
例:shannoEnt -= prob * log(prob,2)
修改为:shannoEnt -= prob * np.math.log(prob,2)
(9)’can't multiply sequence by non-int of type float‘’
解决办法:需要将出错的地方转换数据类型
(10)'itertools cycle' object has no attribute 'next'
原因:编辑版本的原因,出现差错
例:idexer.next( )
修改为:next(idexer)
(11)‘list index out of range’
原因:(1)list[index],index超出范围
(2)list是空列表,进行list[0]就会出错
(12)‘‘int’ object is not iterable’
例:for i in hosts:
修改为:for i in range(hosts):
(13)'unindent does not mach any outer indentation level '
原因:注意缩进,在某行的开头处可能被空格了一下
(14)'could not convert string to float '
原因:(1)可能是文本格式的问题----数据应先在外边的文本.txt编辑后再导入,否则就会引起这种错误的提示
(2)可能在数据分割时出错,将split('\n')改成split(',')
(15)'only length-1 arrays can be converted to python scalars'
原因:不要将列表转换成矩阵形式,
例:math.log(a) ----->np.log(a)
(16)list( ) takes at most 1 argument (2 given)
原因:list 至多1个参数
相关文章推荐
- Qt 使用qmake 遇到 warning LNK4042: object specified more than once; extras ignored 错误的处理办法
- windows 2008初体验常见问题: 无线网络"没有正确配置为使用IP协议" 错误解决办法
- python使用socket远程连接错误处理方法
- 【总结】Python 2.x中常见字符编码和解码方面的错误及其解决办法
- Android使用dom4j时报 java.lang.NoClassDefFoundError错误的处理办法
- eclipse编译java程序常见错误处理办法
- 在sphinx中处理使用特殊字符时所引起错误的办法
- 使用wubi安装ubuntu14.04出现的常见错误的解决办法
- Python Pandas库 常见使用错误总结
- Entity Framework7 入门之全功能.NET版本下使用EF7(含源码)另附数据迁移常见错误处理
- Python 2.x中常见字符编码和解码方面的错误及其解决办法 总结
- C#ADO连接修改Paradox表时“操作必须使用一个可更新的查询”错误的处理办法
- myeclipse中使用maven前常见错误及解决办法
- mysql常见错误代码、原因及处理办法
- 【总结】Python 2.x中常见字符编码和解码方面的错误及其解决办法
- 在Jupyter notebook和spyder上用python做数据挖掘,安装使用简介和常见错误
- 使用spring mvc上传文件的常见错误解决办法
- Python使用pip install psycopg2安装psycopg2包出现python setup.py egg_info failed with error code 1 in /tmp/pip-build-YtLeN3/psycopg2错误处理
- nagios常见错误及处理办法
- 使用isql连接Sybase ASE数据库的常见错误及处理方式