List,
__repr__() is exactly what I was looking for :)
You guys rock! Thank you.
-Modulok-
On 11/12/09, Dave Angel wrote:
>
>
> Kent Johnson wrote:
>> On Thu, Nov 12, 2009 at 6:35 AM, Luke Paireepinart
>> wrote:
>>
>>> On Thu, Nov 12, 2009 at 5:29 AM, Jeff R. Allen wrote:
>>>
You are loo
Kent Johnson wrote:
On Thu, Nov 12, 2009 at 6:35 AM, Luke Paireepinart
wrote:
On Thu, Nov 12, 2009 at 5:29 AM, Jeff R. Allen wrote:
You are looking for the __str__ method. See
http://docs.python.org/reference/datamodel.html#object.__str__
Can't you also implement __repr__?
On Thu, Nov 12, 2009 at 6:00 AM, Kent Johnson wrote:
>
>
> Defining __repr__ will give the custom representation when you just
> give the name of the object:
>
> In [5]: class Foo2():
> ...: def __repr__(self):
> ...: return "I'm a Foo2"
> ...:
> ...:
>
> In [6]: f2=Foo2()
>
On Thu, Nov 12, 2009 at 6:35 AM, Luke Paireepinart
wrote:
>
>
> On Thu, Nov 12, 2009 at 5:29 AM, Jeff R. Allen wrote:
>>
>> You are looking for the __str__ method. See
>> http://docs.python.org/reference/datamodel.html#object.__str__
>>
> Can't you also implement __repr__?
Yes, in fact if you ar
On Thu, Nov 12, 2009 at 5:29 AM, Jeff R. Allen wrote:
> You are looking for the __str__ method. See
> http://docs.python.org/reference/datamodel.html#object.__str__
>
> Can't you also implement __repr__?
(bottom-posted for Dave)
-Luke
___
Tutor maillis
You are looking for the __str__ method. See
http://docs.python.org/reference/datamodel.html#object.__str__
class Foo():
def __init__(self):
pass
def __str__(self)
return "hello world!"
-jeff
___
Tutor maillist - Tutor@python.org
To u
On Thu, Nov 12, 2009 at 5:31 AM, Modulok wrote:
> List,
>
> How do I get a print statement to call a class method? I'm using
> python 2.5. I did it long ago, but can't remember how, or even where I
> learned it from. Something like:
>
> class Foo():
> def __init__(self):
> pass
>
> def *
List,
How do I get a print statement to call a class method? I'm using
python 2.5. I did it long ago, but can't remember how, or even where I
learned it from. Something like:
class Foo():
def __init__(self):
pass
def ***part I can't remember goes here***
print "hello world!"