python实现KNN算法中遇到的问题

来源:互联网 发布:sqlserver安装错误 编辑:程序博客网 时间:2024/06/16 15:18

1.缩进问题
IndentationError:uindent does not match any outer indentation level
错误原因:代码中添加了许多注释,打乱了缩进
解决办法:创建一个空白文件,不附带注释的重写代码,即好

2.属性错误
AttributeError:’dict’ object has no attribute ‘iteritems’
这个异常也是由于python3.x与python2.x的差别造成
2.1python3.x中dict methods dict.keys(), dict.items() and dict.values() return “views” instead of lists.
For example, this no longer works: k = d.keys(); k.sort(). Use k = sorted(d) instead (this works in Python 2.5 too and is just as efficient).
2.2the dict.iterkeys(), dict.iteritems() and dict.itervalues() methods are no longer supported.

3.print()函数格式规范
python3.x相较于python2.x有很多变化:
python3.x使用 print( )function 代替 print satatement have been used in python2.x
eg:print x——>print(x)
print (x,y)——>print((x,y))
本以为是print( )格式规范出错,结果是python版本更新的兼容问题,下述博文中详细总结了print()格式规范。   
http://blog.csdn.net/jcjc918/article/details/9354815
注:官方给出的python3中的改进部分“What’s New In Python 3.0”
https://docs.python.org/release/3.1.3/whatsnew/3.0.html

4.魔方变量_magic
以下网址中有详尽的解释。http://www.jianshu.com/p/1112320c5784

0 0
原创粉丝点击