Is this object counter code pythonic

Duncan Booth duncan.booth at invalid.invalid
Mon Apr 10 08:48:04 EDT 2006


jnair at ensim.com wrote:

> Fredrik is then this a valid "property"  use  case and pythonic  to
> get/set a common varibale  across objects

A valid poperty use case would be one where you did something that couldn't 
be done without using a property.

In some other languages you cannot simply change a public attribute into a 
property, so you have to decide up front whether an attribute might ever 
need to become a property. Since most programmers have at best only an 
imperfect knowledge of the future, advice for those programming in such 
languages is to never make attributes public.

Python isn't like that: if it needs to be a property, because you must do 
something which special on either setting or accessing the value, then use 
a property. If you don't need a property today, then just use an attribute. 
You can change it into a property tomorrow when you find it needs to be a 
property.



More information about the Python-list mailing list