网站百度手机端排名怎么查询,北京公交yy优化,网店服务平台,检测asp网站死循环IndentationError: unexpected indent
Python 中强制缩进#xff0c;#xff0c; IndentationError: unexpected indent 缩进错误
这类错误非常常见#xff0c;一般都是由于tab在不同的平台上占用长度不同导致#xff0c;有些事程序员自己直接使用空格或其他来顶替tab。
解…IndentationError: unexpected indent
Python 中强制缩进 IndentationError: unexpected indent 缩进错误
这类错误非常常见一般都是由于tab在不同的平台上占用长度不同导致有些事程序员自己直接使用空格或其他来顶替tab。
解决办法非常简单在所在平台上使用标准的tab进行缩进就OK了。
UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0x80 in position 106: illegal multibyte sequence
编码错误可以通过指定字符集解决 encoding “utf-8”
io.UnsupportedOperation: not readable
文件不可读可能是文件打开模式不对
UnboundLocalError:localvariable ‘a’referenced before assignment
局部作用域引用错误可能原因是 a变量为局部变量未定义不可修改
no module named wx
缺少wx模块缺啥装啥…
sudo apt-get install python-wxtools
SystemError: cannot compile ‘Python.h’
没法解析Python的头文件解决方法:
#先更新下源
sudo apt-get update#安装python-dev
sudo apt-get install python-dev
NameError: name ‘xrange’ is not defined
python版本问题不兼容python3版本的换成range()函数就行了。
ameError: global name ‘time’ is not defined
解决方法import time
NameError: global name ‘datetime’ is not defined
解决方法 from datetime import datetime
typeError: not all arguments converted during string formatting
TypeError: load() got an unexpected keyword argument ‘delimiter’
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xb6 in position 33: invalid start byte
编码错误基本是由中文引起的中文路径、中文编码
ImportError: cannot import name ‘Flask’
原因之一当前路径名取了一个“ flask ”当前文件名为flask
AttributeError: ‘dict’ object has no attribute ‘has_key’
Python3以后删除了has_key()方法python2中可以。
解决方法
ifadict.has_key(key1):#改为
if key1 in adict:
bs4.FeatureNotFound: Couldn’t find a tree builder with the features you requested: lxml. Do you need to install a parser library?
TypeError: object of type ‘map’ has no len()
ZeroDivisionError: float division by zero
map函数后 返回
map(function, iterable, ......)
Python 2.x 返回列表。
Python 3.x 返回迭代器。 只用将iterator 转换成 list 即可 比如 list(map())
TypeError: ‘int’ object is not iterable
不能直接用int进行迭代
报错代码
list(map(frozenset, C1)) #对每一个元素 frozenset
问题在于map这个函数的第二个参数要求可以迭代C1里面的元素也得可以迭代。C1这个列表的每个元素都是int不可迭代应该也是list才行
解决代码
C1.append([item]) #注意item一定要加中括号代表列表 不然C1的元素是intint是不可迭代的执行list(map(frozenset, C1))会报错。
_tkinter.TclError: unknown option “-lable”
一般是参数的名称出现错误
TypeError: select_algorithm() takes 0 positional arguments but 1 was given
错误出现在tkinter为combobox添加选择事件
解决方法 为函数添加参数*argsdef select_algorithm(*args): #为函数添加参数*args
globalalgo_selected
algo_selectedalgorithm_combobox.get()print(algo_selected)
View Code
ModuleNotFoundError: No module named ‘cPickle’
原因python2有cPickle但是在python3下是没有cPickle的
解决办法将cPickle改为pickle即可
TypeError: getOpenFileName(parent: QWidget None, caption: object ”, directory: object ”, filter: object ”, options: QFileDialog.Options 0): argument 1 has unexpected type ‘str’
#argument 1 是指第一个参数#它的意思是第一个参数不应该是str所以查一下这个函数的几个参数就好了#其实是因为缺少第一个参数
filename QFileDialog.getOpenFileName(None, Open File,/) #第三个参数是默认打开路径如果为空则打开当前路径
No module named ‘sklearn.lda’
#from sklearn.lda import LDA 这是sklearn0.16的写法之后的版本没有了lda 可以查一下sklearn各个版本的API#参考链接 https://stackoverflow.com/questions/46775155/no-module-named-sklearn-lda#为了代码的最少更改可以如下解决
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA
ValueError: too many values to unpack
#参考链接http://leonzhan.iteye.com/blog/1720315#上述链接中说这种错误是指一个tuple值赋给一个tuple变量时变量个数不够造成的。如#a, b (1, 2, 3)
#我的错误代码
X, y FileOpener.load_file(filename)#这里的问题是: load_file返回了三个值 X, y, dataset 所以再加一个值来接收改为如下代码
X, ydataset FileOpener.load_file(filename)
未完待续…………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………..