python pycharm錯誤集錦


url:http://www.cnblogs.com/hinimix/p/8016859.html

1, this list creation could be rewritten as a list literal
預先定義了一個list
list1 = [1,2,3,4] #這么用好

list1 = [1,2,3] #這么用不好
list1.append(4)
此時會出現該提示
解決鏈接:https://stackoverflow.com/questions/31063384/when-i-assign-a-list-to-variable-why-pycharm-give-me-a-prompt-that-is-this-list

2, unsupported operand type(s) for -: 'str' and 'int'
文件讀出來的是字符串, 輸入的是字符串,要注意強轉類型

3, write() argument must be str, not None
寫入文件的必須是字符串類型

4, TypeError: 'NoneType' object is not callable
寫裝飾器的時候,返回值的函數如果帶()就會出這個錯
def timer(func):
def test2():
start_time = time.time()
func()
end_time = time.time()
print("時間間隔是: --> %s " % (end_time - start_time) )
return test2()
正確應該這么寫
def timer(func):
def test2():
start_time = time.time()
func()
end_time = time.time()
print("時間間隔是: --> %s " % (end_time - start_time) )
return test2
返回的是test2的內存地址, 然后去調用這個地址, 而不是直接直接test2()

5, auth() takes 0 positional arguments but 1 was given
裝飾器時, 添加

6, dbm.error: db type could not be determined
d = shelve.open('shelve_test.txt'),文件名里的sheleve去掉

7, TypeError: a bytes-like object is required, not 'str'
with open('aoao.cnf', 'wb') as cfg:,打開文件不要用b,直接w

8, TypeError: key: expected bytes or bytearray, but got 'str'
加密時候應該用byte類型,而不是str

9, SyntaxError: bytes can only contain ASCII literal characters.
加密時候應該用ASCII類型,而不是漢字

10, TypeError: Level not an integer or a valid string: <function info at 0x7f9a4081f048>
level=logging.info是大寫level=logging.INFO

11, _gdbm.error: [Errno 11] Resource temporarily unavailable
不知道

12, TypeError: string indices must be integer
類型不對,看看一堆dict里面是不是有str,會導致這樣

13, ValueError: must have exactly one of create/read/write/append mode
文件打開模式有 r,w,a r+,w+,a+,我寫的是rw,不對

14,TypeError: 'builtin_function_or_method' object is not iterable


15, a bytes-like object is required, not 'str'
傳輸進去的字符串需要是byte類型

16, TypeError: write() argument must be str, not bytes
pickle dump的文件是byte類型,所以打開文件不能用w,要用wb

17, TypeError: not all arguments converted during string formatting
print("set dog %s" % dog) 沒寫全, 少寫了%s

18, TypeError: object() takes no parameters
__init__寫成了__int__

20, module 'urllib' has no attribute 'request'
因為python3.X有時候不會將子模塊自動導入進去,所以改成import url.request問題就解決了

21, TypeError: exchange_declare() got an unexpected keyword argument 'type'
將type='fanout'變成exchange_type='fanout'

22, NameError: name 'uuid' is not defined
....from uuid import uuid4


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM