Jump to content
Top3() Redesignated As A Class Property?
3 replies to this topic
Posted 31 May 2013 - 08:00 AM
I'm stuck on page 250 Chapter 7.
"A quick review of the code to the AthleteList class uncovers the source of the
error: the top3() method has been redesignated as a class property."
Where and when was the method top3() redesignated as a class property and by what or whom?
I can see that using @property before the def top3() declaration allow us to access the method as top3, but why is that necessary in the example? Is this something to do with the way a web server works when calling python methods?
Posted 31 May 2013 - 10:52 AM
I'll be honest, and admit that it's not the greatest example.
The reason I used it was primarily to show that any method in a class can be made to appear like it's an attribute. This allows you to hide the implementation detail (that there's a method being called behind the scenes) from the users of your class. This may or may not be important to you.
But... your hunch is right. It's not really needed here, as using the method works just fine. It has nothing to do with the web, either. As I said, above, not the greatest of examples (and it's getting a better treatment in the second edition, which I'm working on right now).
Posted 04 June 2013 - 03:56 AM
Ah ok, thanks. I was stuck trying to figure out what had changed to cause the error and then require the use of @property.
I think the example would be fine if you explicitly state that you have changed the code to illustrate a new concept. I was reading and re-reading to try and track down the change and what had caused it!
Apart from that one minor hang up, I like the format of the book. Definitely one of the easiest to follow programming books I have ever read. Good work!
Posted 04 June 2013 - 04:23 AM
Well... that's high praise indeed! :-) I'm thrilled you enjoyed the book so much.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users