[英]Python Inheritance - TypeError: __init__() takes 1 positional argument but 4 were given
import requests
class Poll(requests.session()):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
with Poll() as p:
# do stuff
>>TypeError: __init__() takes 1 positional argument but 4 were given
I don't understand why an error is being thrown.我不明白为什么会抛出错误。 Doesn't *args take care of any extra positional arguments? *args 不处理任何额外的位置参数吗?
Found the issue.发现问题。 requests.session is a function that returns an instance of the class requests.Session. requests.session 是一个函数,它返回类requests.Session 的一个实例。
Fixed code:固定代码:
import requests
class Poll(requests.Session):
def __init__(self):
super().__init__()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.