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
posted @ 2019-10-04 18:02  jiangxiaobo  阅读(2844)  评论(0编辑  收藏  举报