general class functions

syd syd.diamond at gmail.com
Wed Nov 3 11:18:36 EST 2004


"Dan Perl" <danperl at rogers.com> wrote in message 
> >>>> library.get_continent('Europe')
> This line creates and returns an instance of Library.  I assume that you 
> imported foo in a python session and then you executed that line.  That 
> results in a call to Library.__repr__( ), which is not defined.  First of 
> all, I recommend you change class Library to subclass from object.  That's 
> just good practice in general and in this case it will give you a default 
> __repr__( ) method.  But that's probably not what you want.  What you 
> probably want is to still use a line like:
>     print library.getContinent('Europe').getNameList()
> Otherwise, library.get_continent('Europe') is going to print something like:
>     <__main__.Library object at 0x00A9F430>

You're 100% right, Dan -- I meant to have the "getNameList()" tacked
on.

But more importantly, why is subclassing object a good practice in
general?  I see under dir(object) that you get some good default
methods.  I looked under the documentation, but could not find a good
specific examples as to why this was a good practice.  Can you
elaborate, please?



More information about the Python-list mailing list