0

I'm beginner with Python. I know only C++/C# so... My problem is append to my array some object which is Card with 2 parameters, card has color and value

part of code doesn't work

class Game: 
    table = []
    ....
    def play(self, *players):
        for singlePlayer in players:
            self.table.append(singlePlayer.throwCard())

function throwCard() in Player

def throwCard(self):
    cardToThrow = self.setOfCards[0]
    del self.setOfCards[0]
    return cardToThrow

"main"

player1 = Player()
player2 = Player()
game = Game()
game.play([player1, player2])

Do you have some suggestions?

AttributeError: 'list' object has no attribute 'throwCard'

10
  • 1
    What is inside players list? Commented Jun 30, 2017 at 13:42
  • I tink the problem is more with singlePlayer. Apparently that is not a Player, but a list... Commented Jun 30, 2017 at 13:43
  • players is an array of? Commented Jun 30, 2017 at 13:43
  • 2
    You should post a full minimal reproducible example. Commented Jun 30, 2017 at 13:47
  • 2
    remove the asterisk, you just need def play(self, players):. With the asterisk you actually get a tuple of a list of players. Commented Jun 30, 2017 at 13:50

2 Answers 2

2

try changing:

def play():

to:

def play(self,players):

should do it.

Sign up to request clarification or add additional context in comments.

Comments

1
class Game:
    # ...
    def play(self, *players):
        # ...

this play method requires arguments to be flat, not giving a list explicitly. I mean, you should ...

# your main
game.play(player1, player2)

check this SO post.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.