[Tutor] static methods and class methods

wesley chun wescpy at gmail.com
Wed Jun 11 10:28:00 CEST 2008


>>>> tcm.foo
> <bound method classobj.foo of <class __main__.TestClassMethod at 0xb7da0f2c>>
>
> Did I do something wrong or is this an error on the book's part?  Intuitively, the answer I received makes more sense to me.  I am still unsure of the difference of static and class methods.  Can someone enlighten me?


hi there,

thanks for picking up the book.  there are definitely some typos in
the book, but this isn't one of them.

marilyn is correct, instead of *calling* the method, you asked the
interpreter to show you what object it represents [repr() for those if
you who know].

tcm.foo <--- that is a function/method object that is callable
tcm.foo() <-- actually call the function and return its output

all you did wrong was to ask for the object instead of calling it.

hope this helps!
-- wesley

ps. be sure to check out the Errata page at the book's website to get
all the corrections... i'll be updating it within a few days with the
latest changes.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
 http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com


More information about the Tutor mailing list