0

我试图理解这个程序,以便更好地掌握 Python 编程。我正在摆弄该程序并试图弄清楚如何运行它,但是每次我包含一个 play_pigs() 调用时,我都会收到一个错误,说需要参数。这是真的,因为代码说它需要一个“(自我)”参数,

def play_pigs(self):

那么这个程序是如何运行的呢?我不是很了解这部分,但我想我了解代码的其他一些部分。

代码:http: //ideone.com/LuRLOu

4

1 回答 1

1

play_pigs() is a method of the class PlayerSet. You will have to get (e. g. create) an instance of this class on which you then can call play_pigs() like this, for instance:

playerSet = PlayerSet(1, "foo")  # or some other way to get such an instance
playerSet.play_pigs()  # do not pass "self" here, as this is implicit already

This answers your direct question. I didn't check if this works at all since this would be out of the scope of SO.

于 2013-09-30T08:36:17.373 回答