我目前正在为 Snapchat 广告编写 API 连接器。我写了一个类。但是,在测试时,我看到了不寻常的行为。下面的代码说明了这种行为。使用 3.7 版
import requests
from requests_oauthlib import OAuth2Session
import datetime as dt
class SnapchatAPI(object):
def __int__(self, client_id, client_secret, org_id):
self.client_id = client_id
self.client_secret = client_secret
self.org_id = org_id
比如上面是类的声明。当我运行它并尝试在没有参数的情况下实例化它时。它仍然有效。[它不应该。但确实如此]。我无法弄清楚为什么SnapchatAPI() 没有提高和错误就可以工作?
extractor = SnapchatAPI()
然而,在试图弄清楚我回到了像下面这样的简单类来检查行为时
class Person(object):
def __init__(self, firstname, lastname, address):
self.firstname = firstname
self.lastname = lastname
self.address = address
当我尝试在没有参数的情况下实例化它时。它引发了一个错误。这是我所期望的
john_doe = Person()
Traceback (most recent call last):
File "<pyshell>", line 1, in <module>
TypeError: __init__() missing 3 required positional arguments: 'firstname', 'lastname', and 'address'
想不通为什么!
跃然一笑
临摹微笑
随时随地看视频慕课网APP
相关分类