Python 类 和自己

Python Classes and the self

我有一个关于 Classes 和 self. 的初学者问题 我的函数 checkAbonnement 现在看起来像这样:

    def checkAbonnement(self):
    # Create Labels and Buttons
       self.text = Label(text="Choose the Subscription you got")
       self.text.grid(row=1, column=0)
       self.aboButton = Button(window, text="No Subscription", command=lambda:[self.setAbonnement(1), self.checkGutschein()])
       self.aboButton.grid(row=2, column=0)
       self.aboButton_2 = Button(window, text="Silver Subscription", command=lambda:[self.setAbonnement(2), self.checkGutschein()])
       self.aboButton_2.grid(row=3, column=0)
       self.aboButton_3 = Button(window, text="Gold Subscription", command=lambda:[self.setAbonnement(3), self.checkGutschein()])
       self.aboButton_3.grid(row=4, column=0)
       self.aboButton_4 = Button(window, text="Platinum Subscription", command=lambda:[self.setAbonnement(4), self.checkGutschein()])
       self.aboButton_4.grid(row=5, column=0)

如你所见,里面有一堆 self....

我现在的问题是:除了使用 self.

之外,是否需要它们或者是否有更好的选择向我的 Class 声明它们
class ScooTeq:

如果您希望这些属性在 ScooTeq 的实例中是唯一的,那么您必须使用 self。我同意这可能很乏味,但这是为了避免歧义。关于此 here.

有更多信息