Re: Can you use self in __str__

2014-12-04 Thread Jean-Michel Pichavant
- Original Message - From: Seymore4Head Seymore4Head@Hotmail.invalid To: python-list@python.org Sent: Friday, 28 November, 2014 4:31:50 AM Subject: Re: Can you use self in __str__ On Thu, 27 Nov 2014 21:49:29 -0500, Dave Angel da...@davea.name wrote: class Hand: def

Re: Can you use self in __str__

2014-12-04 Thread Seymore4Head
On Thu, 4 Dec 2014 20:22:11 +0100 (CET), Jean-Michel Pichavant jeanmic...@sequans.com wrote: - Original Message - From: Seymore4Head Seymore4Head@Hotmail.invalid To: python-list@python.org Sent: Friday, 28 November, 2014 4:31:50 AM Subject: Re: Can you use self in __str__ On Thu

Re: Can you use self in __str__

2014-11-28 Thread Steven D'Aprano
Seymore4Head wrote: def __str__(self): s = Hand contains for x in self.hand: s = s + str(x) + return s This is part of a Hand class. I need a hand for the dealer and a hand for the player. dealer=Hand() player=Hand() This prints out 'Hand

Re: Can you use self in __str__

2014-11-28 Thread Dave Angel
On 11/27/2014 10:31 PM, Seymore4Head wrote: On Thu, 27 Nov 2014 21:49:29 -0500, Dave Angel da...@davea.name wrote: class Hand: def __init__(self): self.hand = [] # create Hand object def __str__(self): s = 'Hand contains ' for x in self.hand:

Re: Can you use self in __str__

2014-11-28 Thread Chris Angelico
On Fri, Nov 28, 2014 at 12:26 PM, Seymore4Head Seymore4Head@hotmail.invalid wrote: dealer=Hand() player=Hand() This prints out 'Hand contains foo bar for both the dealer's hand and the player's hand. Is there a way to include self in the __string__ so it reads Dealer hand contains foo bar

Re: Can you use self in __str__

2014-11-28 Thread Dave Angel
On 11/27/2014 08:43 PM, Chris Angelico wrote: On Fri, Nov 28, 2014 at 12:26 PM, Seymore4Head Seymore4Head@hotmail.invalid wrote: dealer=Hand() player=Hand() This prints out 'Hand contains foo bar for both the dealer's hand and the player's hand. Is there a way to include self in the

Re: Can you use self in __str__

2014-11-28 Thread Rustom Mody
On Friday, November 28, 2014 6:57:23 AM UTC+5:30, Seymore4Head wrote: def __str__(self): s = Hand contains for x in self.hand: s = s + str(x) + return s This is part of a Hand class. I need a hand for the dealer and a hand for the player.

Re: Can you use self in __str__

2014-11-28 Thread Rustom Mody
On Friday, November 28, 2014 7:51:40 PM UTC+5:30, Rustom Mody wrote: On Friday, November 28, 2014 6:57:23 AM UTC+5:30, Seymore4Head wrote: def __str__(self): s = Hand contains for x in self.hand: s = s + str(x) + return s This is part of a

Re: Can you use self in __str__

2014-11-28 Thread Shiyao Ma
2014-11-28 13:00 GMT+08:00 Chris Angelico ros...@gmail.com: On Fri, Nov 28, 2014 at 2:04 PM, Shiyao Ma i...@introo.me wrote: What if it's in the local namespace of a function or method? IDK, try to get that thing first. Sure enough. I will even avoid using id as it's dependent on CPython

Re: Can you use self in __str__

2014-11-28 Thread Chris Angelico
On Sat, Nov 29, 2014 at 2:16 PM, Shiyao Ma i...@introo.me wrote: 2014-11-28 13:00 GMT+08:00 Chris Angelico ros...@gmail.com: On Fri, Nov 28, 2014 at 2:04 PM, Shiyao Ma i...@introo.me wrote: What if it's in the local namespace of a function or method? IDK, try to get that thing first. Sure

Re: Can you use self in __str__

2014-11-28 Thread Shiyao Ma
2014-11-29 11:36 GMT+08:00 Chris Angelico ros...@gmail.com: You can use id() on any object. You are guaranteed to get back an integer which is both stable and unique among all ids of objects that exist at the same time as the one you called it on. For as long as the object continues to exist,

Can you use self in __str__

2014-11-27 Thread Seymore4Head
def __str__(self): s = Hand contains for x in self.hand: s = s + str(x) + return s This is part of a Hand class. I need a hand for the dealer and a hand for the player. dealer=Hand() player=Hand() This prints out 'Hand contains foo bar for both the

Re: Can you use self in __str__

2014-11-27 Thread Dave Angel
On 11/27/2014 08:26 PM, Seymore4Head wrote: def __str__(self): s = Hand contains for x in self.hand: s = s + str(x) + return s This is part of a Hand class. I need a hand for the dealer and a hand for the player. dealer=Hand() player=Hand()

Re: Can you use self in __str__

2014-11-27 Thread Shiyao Ma
2014-11-28 9:26 GMT+08:00 Seymore4Head Seymore4Head@hotmail.invalid: def __str__(self): s = Hand contains for x in self.hand: s = s + str(x) + return s This is part of a Hand class. I need a hand for the dealer and a hand for the player.

Re: Can you use self in __str__

2014-11-27 Thread Seymore4Head
On Thu, 27 Nov 2014 21:49:29 -0500, Dave Angel da...@davea.name wrote: class Hand: def __init__(self): self.hand = [] # create Hand object def __str__(self): s = 'Hand contains ' for x in self.hand: s = s + str(x) + return s I am

Re: Can you use self in __str__

2014-11-27 Thread Seymore4Head
On Fri, 28 Nov 2014 11:04:26 +0800, Shiyao Ma i...@introo.me wrote: 2014-11-28 9:26 GMT+08:00 Seymore4Head Seymore4Head@hotmail.invalid: def __str__(self): s = Hand contains for x in self.hand: s = s + str(x) + return s This is part of a Hand

Re: Can you use self in __str__

2014-11-27 Thread Chris Angelico
On Fri, Nov 28, 2014 at 2:04 PM, Shiyao Ma i...@introo.me wrote: What if it's in the local namespace of a function or method? IDK, try to get that thing first. What if it's in multiple namespaces? What if it's not in any at all? Your solution is not going to work in the general case, AND it's a

Re: Can you use self in __str__

2014-11-27 Thread Steven D'Aprano
Seymore4Head wrote: On Fri, 28 Nov 2014 11:04:26 +0800, Shiyao Ma i...@introo.me wrote: 2014-11-28 9:26 GMT+08:00 Seymore4Head Seymore4Head@hotmail.invalid: def __str__(self): s = Hand contains for x in self.hand: s = s + str(x) + return s This