On Thu, 4 Dec 2014 20:22:11 +0100 (CET), Jean-Michel Pichavant
wrote:
>- Original Message -
>> From: "Seymore4Head"
>> To: python-list@python.org
>> Sent: Friday, 28 November, 2014 4:31:50 AM
>> Subject: Re: Can you use self in __str__
>>
- Original Message -
> From: "Seymore4Head"
> 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
> wrote:
>
> class Hand:
>
2014-11-29 11:36 GMT+08:00 Chris Angelico :
> 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, that number *
On Sat, Nov 29, 2014 at 2:16 PM, Shiyao Ma wrote:
> 2014-11-28 13:00 GMT+08:00 Chris Angelico :
>> On Fri, Nov 28, 2014 at 2:04 PM, Shiyao Ma 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
2014-11-28 13:00 GMT+08:00 Chris Angelico :
> On Fri, Nov 28, 2014 at 2:04 PM, Shiyao Ma 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
implementation. :)
> What i
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
> >
> > Thi
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.
On 11/27/2014 08:43 PM, Chris Angelico wrote:
On Fri, Nov 28, 2014 at 12:26 PM, Seymore4Head
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
On Fri, Nov 28, 2014 at 12:26 PM, Seymore4Head
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
> Player hand conta
On 11/27/2014 10:31 PM, Seymore4Head wrote:
On Thu, 27 Nov 2014 21:49:29 -0500, Dave Angel
wrote:
class Hand:
def __init__(self):
self.hand = []
# create Hand object
def __str__(self):
s = 'Hand contains '
for x in self.hand:
s = s + s
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 print
Seymore4Head wrote:
> On Fri, 28 Nov 2014 11:04:26 +0800, Shiyao Ma wrote:
>
>>2014-11-28 9:26 GMT+08:00 Seymore4Head :
>>> def __str__(self):
>>> s = "Hand contains "
>>> for x in self.hand:
>>> s = s + str(x) + " "
>>> return s
>>>
>>> This is part of a
On Fri, Nov 28, 2014 at 2:04 PM, Shiyao Ma 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 bad
idea. Pl
On Fri, 28 Nov 2014 11:04:26 +0800, Shiyao Ma wrote:
>2014-11-28 9:26 GMT+08:00 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 th
On Thu, 27 Nov 2014 21:49:29 -0500, Dave Angel
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 using 2.7 (Codesku
2014-11-28 9:26 GMT+08:00 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=
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()
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 th
18 matches
Mail list logo