Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如果达到异常x次数,如何调用函数_Python_Python 3.x - Fatal编程技术网

Python 如果达到异常x次数,如何调用函数

Python 如果达到异常x次数,如何调用函数,python,python-3.x,Python,Python 3.x,我一直在编写一个脚本,其中我想做一个异常计数器,向我的discord报告(我们可以称之为discord\u notify())一个特定异常连续5次达到限制,等等 我做过类似他的事 main.py 从lib.exceptions导入( 类型例外 ) candy=“紫色” 价格=“130欧元” 尽管如此: 尝试: 类型(int(“字符串”)) 例外情况除外,如e: 从e中引发TypeException({'Unexpected type error':5},candy=candy,price=pri

我一直在编写一个脚本,其中我想做一个异常计数器,向我的discord报告(我们可以称之为
discord\u notify()
)一个特定异常连续5次达到限制,等等

我做过类似他的事

main.py

从lib.exceptions导入(
类型例外
)
candy=“紫色”
价格=“130欧元”
尽管如此:
尝试:
类型(int(“字符串”))
例外情况除外,如e:
从e中引发TypeException({'Unexpected type error':5},candy=candy,price=price)
库异常


类类型异常:
"""
为异常引发异常
"""
lib.utils

从集合导入defaultdict
从键入import DefaultDict,Dict,键入
类例外计数器:
"""
计数器检查是否连续x次出现异常。
"""
定义初始化(自):
自我限制=限制
self.exception_计数:DefaultDict[类型[异常],int]=DefaultDict(int)
def检查(自身、异常:异常、允许计数:int):
异常\名称=类型(异常)。\名称__
self.exception\u计数[exception\u name]+=1
如果self.exception\u计数[异常\u名称]>=允许的\u计数:
提升
def重置(自):
self.exception\u counts.clear()
我的问题是,我不知道如何从e部分向我的
lib.utils
传递
raisetypeexception({'Unexpected type error':5},candy=candy,price=price),稍后我想通过向
discord.notify(msg,candy,price)

我该怎么做