英文:
applying Singleton to Spotipy throws error
问题
Spotipy的对象需要传递一个凭据的kw参数
我的代码:
import spotipy
class Spoti2(spotipy.Spotify):
spoty_obj = None
@classmethod
def __new__(cls, client_credentials_manager):
if cls.spoty_obj is None:
cls.spoty_obj = super().__new__(cls)
print('实例已创建')
return cls.spoty_obj
但是我得到了错误:
Spoti2.__new__()为参数'client_credentials_manager'获得了多个值
然而,当我移除@classmethod
时,它可以工作,我不知道为什么
英文:
Spotipy's object needs to be passed a credential kw arg
my code:
import spotipy
class Spoti2(spotipy.Spotify):
spoty_obj = None
@classmethod
def __new__(cls, client_credentials_manager):
if cls.spoty_obj is None:
cls.spoty_obj = super().__new__(cls)
print('se creo instancia')
return cls.spoty_obj
but i get the error:
Spoti2.__new__() got multiple values for argument 'client_credentials_manager'
however, when I remove @classmethod
, it works, and I don't know why
答案1
得分: 1
"你不应该将 @classmethod
添加到 __new__()
"
来自:https://docs.python.org/3/reference/datamodel.html#object.new
特殊情况,因此您无需将其声明为[静态/类方法]。
英文:
You're not supposed to add @classmethod
to __new__()
From: https://docs.python.org/3/reference/datamodel.html#object.__new__
> special-cased so you need not declare it as [a static/class method]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论