[Tutor] New class, how return value of x in interactive shell

Alan Gauld alan.gauld at btinternet.com
Mon Apr 5 21:08:24 CEST 2010


"Vincent Davis" <vincent at vincentdavis.net> wrote 

>I am working an a open source project and would like to add feature to a
> class.
> Current action:
> in:    >>>b = BString.new('I am a BString object')

That' a very strange idiom in Python.
Can you show us the class definition?

> out:  >>>b
> in:    >>><BString - Python:0x1044846c8 / R:0x105c86f50>
> in:    >>>print(b)
> out:  >>> 21-letter "BString" instance
>               seq: I am a BString object
> 
> What I would like is to be able to
> in   >>>b
> out >>>21-letter "BString" instance
>               seq: I am a BString object
> 
> I have 2 questions
> 1, how do I do this?
> 2, how does print know what to do?

If you look at your class definition that should become obvious.
Are you sure this isn't a homework?


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list