标签:elf *args 单例 obj return ret print def class
# pcj
class Musicplay(object):
id=None
def __new__(cls, *args, **kwargs):
if cls.id is None:
cls.id=super().__new__(cls) #new是一个静态方法。所以要传cls参数
return cls.id
def __init__(self):
print("音乐初始化中........")
music1=Musicplay()
music2=Musicplay()
print(music1)
print(music2)
标签:elf *args 单例 obj return ret print def class
原文地址:https://www.cnblogs.com/pcjbk/p/11279765.html