考虑:
代码
class sand:
def __init__(self):
print("I am a pickle")
def next(self):
print("I am a tuner")
测试并输出
>>> x = sand()
I am a pickle
>>> x.next()
Traceback (most recent call last):
File "<pyshell#26>", line 1, in <module>
x.next()
AttributeError: 'sand' object has no attribute 'next'
请您参考如下方法:
没有属性 next 因为你的缩进不正确。使用:
class sand:
def __init__(self):
print("I am a pickle")
def next(self):
print("I am a tuner")
x = sand()
x.next()
输出
I am a pickle
I am a tuner
