Re: [Tutor] How to call a method with a print statement?

2009-11-13 Thread Modulok
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

Re: [Tutor] How to call a method with a print statement?

2009-11-12 Thread Dave Angel
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__?

Re: [Tutor] How to call a method with a print statement?

2009-11-12 Thread Wayne Werner
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() >

Re: [Tutor] How to call a method with a print statement?

2009-11-12 Thread Kent Johnson
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

Re: [Tutor] How to call a method with a print statement?

2009-11-12 Thread Luke Paireepinart
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

Re: [Tutor] How to call a method with a print statement?

2009-11-12 Thread Jeff R. Allen
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

Re: [Tutor] How to call a method with a print statement?

2009-11-12 Thread Kent Johnson
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  *

[Tutor] How to call a method with a print statement?

2009-11-12 Thread Modulok
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!"