python运行报错
1、運行出現object()takes no parameters錯誤
一開始沒發覺,然后發現__init__(Ctrl+/驗證是雙短橫線,我只用了一個短橫線)
2、Type error:takes0 positional arguments but 1 was given
可能是因為你定義的類中某個方法名后的小括號()中沒有寫self
?
3、在編譯時會出現這樣的錯Indentation Error:expected an indented block
說明此處需要縮進,你只要在出現錯誤的那一行,按空格或Tab(但不能混用)鍵縮進就行。
4、syntaxerror: invalid syntax
“非法語句”。漏標點符號(例如漏分號,&號等),多標點符號,拼寫錯誤等等都會造成這種錯誤。
5、pycharm 編寫程序使 import無法通過。
這是由于該程序不在根目錄下,無法導入本地包,解決辦法如下:
(1)清除緩存并重啟:(File -> Invalidate Caches / Restart...)
(2)設置源目錄(注意設置哪個目錄,這里設置的是test_suite)(右鍵源目錄 -> Make Directory as -> Sources Root)
6、python "TypeError: 'NoneType' object is not iterable"錯誤分析
使用如下的調用時,會報錯:"TypeError: 'NoneType' object is not iterable"
[python]?view plain?copyTypeError: 'NoneType' object is not iterable ?這個錯誤提示一般發生在將None賦給多個值時。
如 a,b,c,d = None
就會這樣報錯。
這里是沒有考慮到else的情況,在if條件不滿足時,函數默認返回None。
調用時,將None賦給 flag, val
就出現了這樣的錯誤提示。
【結論】
a.?將None賦給多個值時,會出現提示:TypeError: 'NoneType' object is not iterable
b. 函數返回值一定要考慮到條件分支的覆蓋
c. 在沒有return語句時,python默認會返回None
7.Cannot uninstall chardet
問題描述:
I've been trying to uninstall chardet using pip, but I get the following error:
"Cannot uninstall 'chardet'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall."
解決辦法:
The location of chardet can be determined by running the following commands in the python console.
>>> import chardet >>> print chardet.__file__ /usr/lib/python2.7/dist-packages/chardet/__init__.pycThen just manually remove the following folders/*.egg-info file.
rm /usr/lib/python2.7/dist-packages/chardet-<your-version>.egg-info rm -r /usr/lib/python2.7/dist-packages/chardet總結
以上是生活随笔為你收集整理的python运行报错的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python assert断言的用法
- 下一篇: python 拾遗(一)