Ant wrote:
> We seem to be flogging a dead horse now. Is the following a fair
> summary:
>
> Q. What is the Pythonic way of implementing getters and setters?
>
> A. Use attributes.
>
> Quote: "I put a lot more effort into choosing method and function
> names"
>
> Wisdom: Python is a different paradigm from (e.g.) Java w.r.t.
> accessors: Put the effort you would have put into choosing accessor
> names into choosing attribute names.
>
> Anything else to add to this? Or can it be put to bed?

Here are the lessons I've learned (the hard way).

1) Make all attributes of a class private or protected. You can make
them public later if need be. If anyone tells you making attributes
private/protected is not Pythonic ignore them. You'll thank me when
your code base grows.
2) If a data attribute might likely be an API, think about controlling
access to via "properties". That's the pythonic way to implement
accessors and mutators

I guess people who've done medium to large scale programming in Python
already know this.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to