[Tutor] Python OOP question

Alan Gauld alan.gauld at btinternet.com
Sat Apr 2 20:45:48 EDT 2016


On 02/04/16 22:46, Eric Enoch wrote:

> of BJ player is ultimately BJ hand. I am now getting an error when calling
> a method to add a card to that hand. Below is where the error o

Unfortunately you don't show us the actual code where you call
that method, nor do you show us the actual error (in full).
As a result its hard to guess what's going on.

Please post the actual code where you call the method and the
full error traceback.

> class BJ_Game(object): """ A Blackjack Game. """ def *init*(self, names,
> startingmonies):
> self.players = [] for name in names: player = BJ_Player(name) spot =
> names.index(name) startingscratch = startingmonies[spot] player_with_money
> = (name, startingscratch,0) self.players.append(player_with_money)

We also seem to have lost the formatting, probably due to not
posting in plain text. HTML/RTF mail tends to get spacing
messed up, please always use plain text when posting code.

> def give(self, card, other_hand):
>     self.cards.remove(card)
>     other_hand.add(card)
> 
> This is the error that I get.: line 47, in give other_hand.add(card)
> AttributeError: 'tuple' object has no attribute 'add'

This suggests you are passing a tuple into the method when you
call it. But without either the full traceback or the calling
code we can only guess.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list