使用python中常见的错误及处理办法(1)
来源:互联网 发布:哪些网络销售软件好用 编辑:程序博客网 时间:2024/05/29 16:08
(1)invalid literal for int( ) with base 10:'largeDoses'
解决办法:这是因为数据类型不一致,导致出错,在int/str/float转换,其中raw_input接收字符串,input接收整数
(2)‘ ^
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个参数
- 使用python中常见的错误及处理办法(1)
- 常见警告及处理办法
- C++编译中常见的一些警告信息及处理办法(未完待续)
- Linux/Ubuntu中tr命令的使用及常见错误
- LoadRunner 常见的错误及处理方法
- 常见网络攻击及处理办法
- 编程中常见的错误处理方式
- python 常见异常错误处理
- myeclipse中遇到tomcat jdk name错误处理的办法
- Delphi2007中提示Application.Exename错误的处理办法
- <转载>Python中新手常见的错误
- python中常见的几种错误
- Java中常见内存溢出错误及处理方法
- linux错误检测及处理办法
- android中常见的错误及解决办法
- android中常见的错误及解决办法
- android中常见的错误及解决办法
- python中常见的字符串处理函数
- 微信jssdk调用地图(openLocation)小坑
- wordCount MapReduce
- vs2012配置boost库 (快捷,完全,定制)安装
- 游戏任务标记
- 欢迎使用CSDN-markdown编辑器
- 使用python中常见的错误及处理办法(1)
- 20170911在CVTE的面试总结
- C++中vector利用algorithm库寻找最大值
- oracle 自动内存管理介绍,虚机扩内存后调整oracle 内存占用
- 想想毕业我去哪,做什么,能做什么,该怎么做
- python3-元组小练习
- 非阻塞队列ConcurrentLinkedQueue之容器初步学习
- 《JAVA与模式》之责任链模式
- 104. Maximum Depth of Binary Tree