日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

用pycharm写python老是提示错误_python pycharm错误集锦

發布時間:2025/3/8 python 14 豆豆
生活随笔 收集整理的這篇文章主要介紹了 用pycharm写python老是提示错误_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:

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

總結

以上是生活随笔為你收集整理的用pycharm写python老是提示错误_python pycharm错误集锦的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。