出错啦!
class Player:instance = None
init_flag = False
def __new__(cls,yy):
def __init__(self):
if Player.init_flag:
return
print("初始化")
Player.init_flag = True
p1 = Player()
print(p1)
p2 = Player()
print(p2)
File "C:\Users\tlan2\PycharmProjects\david\jj.py", line 8
def __init__(self):
^
IndentationError: expected an indented block
Process finished with exit code 1
怎么解决
缩进删了重打试试 class Player:
instance = None
init_flag = False
def __new__(cls,yy):
pass
def __init__(self):
if Player.init_flag:
return
print("初始化")
Player.init_flag = True IndentationError: expected an indented block
IndentationError 看到这个不用想,就是缩进错误,记住就好。 1q23w31 发表于 2020-8-13 07:54
new方法要返回对象!! 革命年 发表于 2020-8-13 22:23
new方法要返回对象!!
那你要把new写完整啊,什么都不写,定义不完全,当然报错
页:
[1]