Automatic Generation of Python Class Files

Steven Bethard steven.bethard at
Mon Oct 22 20:48:21 CEST 2007

Sunburned Surveyor wrote:
> I also intended to add statements creating properties from the getter
> and setter methods. I understand that getters and setters aren't
> really necessary if you aren't making a property. I just forgot to add
> the property statements to my example.

You still don't want to define the getters and setters if they're just 
going to set an attribute. Just use an attribute itself.

Java makes you define getters and setters because there's no way to make 
method calls look like an attribute access.  So in Java if you start 
with a public attribute, you can never adjust the API later.

In Python, you can use property() to make method calls look like 
attribute access.  This could be necessary if you have an existing API 
that used public attributes, but changes to your code require those 
attributes to do additional calculations now.

But if you're creating a class for the first time, it should *never* use 
property().  There's no need to retrofit anything.


More information about the Python-list mailing list