Computer Science Canada [python-tip] Properties |
Author: | wtd [ Mon Sep 29, 2008 12:56 am ] | ||||||||
Post subject: | [python-tip] Properties | ||||||||
Frequently I see code like the following.
Now, obviously we don't need get_bar in this case because the bar field is public. The set_bar function is not strictly necessary either. But, making attributes of an object private is a good idea, so...
But now our code has to look all Java-like with explicit setters and getters. Ugly. What if we could keep the attribute private but still use:
There is!
Use your new power responsibly. |