持续更新中...html
__enter__
Python3.7环境相关:http://www.javashuo.com/article/p-tvzhtwbx-bq.htmlpython
===>检查一下缩进,能够借用yapf或者pycodestyle来帮忙
能够参考这篇文章的末尾:http://www.javashuo.com/article/p-tvzhtwbx-bq.htmlmysql
==> def str(self) 里面没有return返回值
web
==>'list'对象不可调用,通常都是用户自定变量和list重名了
sql
缘由:
django
==>装饰实例方法
的时候容易出现莫名其妙的错误,因此通常加上get方法,来个案例:async
import types from functools import wraps class Log(object): def __init__(self, func): wraps(func)(self) # @wraps(func) 访问不到,因此用这种方式 self.__func = func def __call__(self, *args, **kvs): print("%s log_info..." % self.__func.__name__) return self.__func(*args, **kvs) # 装饰实例方法的时候容易出现莫名其妙的错误,因此通常加上get方法 # eg:show() missing 1 required positional argument: 'self' def __get__(self, instance, cls): if instance is None: return self else: return types.MethodType(self, instance) class LoginComponent(object): def __init__(self, name): self.__name = name @Log def show(self): """实例方法""" print("欢迎你:%s" % self.__name) @classmethod @Log # 写在下面("从下往上装,从上往下拆") def login_in(cls): """类方法""" print("登陆ing") @staticmethod @Log def show_news(): """静态方法""" print("今天的新闻是...") def main(): LoginComponent.login_in() LoginComponent.show_news() login = LoginComponent("小明") login.show() if __name__ == '__main__': main()
缘由:命令不规范,或者你导入的模块当作类来使用了ide
好比今天写demo的时候,随手建立了个文件名:mmap.py
函数
import mmap fd = os.open("mmap_file", os.O_RDWR) # 读+写 m = mmap.mmap(fd, 0) # 建立映射
导入的模块也是mmap,那问题就来了~因此,就算随手测试也是要命名规范的-_-#测试
__enter__
通常都是上下文管理器with xxx as x:
的问题,看看是否不能托管的进行了托管,或者自定义上下文管理器__enter__
方法有问题
通常都是编码问题,Linux一切正常,win下面出现了糟心事
解决:
指定编码:头文件包含# _*_ coding:utf-8 _*_
and 指定编码格式 encoding="utf-8"
还出现错误就忽略吧:errors='ignore'
eg:with open("bai.csv","r",errors='ignore') as f:
队列对象只能经过继承进程之间共享,由于用到了Pool,multiprocessing.Queue()
会有点问题,换为multiprocessing.Manager().Queue()
便可
http://www.javashuo.com/article/p-hufkkonm-d.html
具体能够查看此文章:http://www.javashuo.com/article/p-phkqmcgd-v.html
http://www.javashuo.com/article/p-qdnbxexf-bx.html
Win下Py包安装出错就去这个网站下对应包:https://www.lfd.uci.edu/~gohlke/pythonlibs/
而后 pip install xxx
去PyPI搜索包,而后左侧菜单栏有下载连接
以后pip install xxx 便可
解决:http://www.javashuo.com/article/p-auijtlyq-ck.html
http://www.javashuo.com/article/p-acwbbimg-cv.html
有些异常官方没有写进去,我补了一些经常使用的异常:https://docs.python.org/3/library/exceptions.html
BaseException
SystemExit
:sys.exit()
引起的异常(目的:让Python解释器退出)KeyboardInterrupt
:用户Ctrl+C终止程序引起的异常GeneratorExit
:生成器或者协程关闭的时候产生的异常(特别注意)Exception
:全部内置异常(非系统退出)或者用户定义异常的基类
asyncio.Error
asyncio.CancelledError
asyncio.TimeoutError
:和Exception.OSError.TimeoutError
区分开asyncio.InvalidStateError
:Task/Future
内部状态无效引起asyncio.LimitOverrunError
:超出缓冲区引起的异常StopIteration
:next()、send()
引起的异常:
https://www.cnblogs.com/dotnetcrazy/p/9278573.html#6.Python迭代器
StopAsyncIteration
:__anext__()
引起的异常AssertionError
:当断言assert
语句失败时引起AttributeError
:当属性引用或赋值失败时引起EOFError
asyncio.IncompleteReadError
:读取操做未完成引起的错误OSError
:当系统函数返回与系统相关的错误时引起
TimeoutError
:系统函数执行超时时触发ReferenceError
:引用错误(对象被资源回收或者删除了)RuntimeError
:出错了,可是检测不到错误类别时触发
NotImplementedError
:为实现报错(好比调用了某个不存在的子类方法)RecursionError
:递归程度太深引起的异常asyncio.SendfileNotAvailableError
:系统调用不适用于给定的套接字或文件类型SyntaxError
:语法错误时引起(粘贴代码常常遇到)
IndentationError
:缩进有问题TabError
:当缩进包含不一致的制表符和空格使用时引起