use member functions to access data in Python classes?

Gerhard Häring gh at ghaering.de
Wed Jun 18 12:30:43 EDT 2003


beliavsky at aol.com wrote:
> In C++, it is generally recommended to declare the data within a class
> private and to access the data using member functions. Do experienced
> Python programmers usually use member functions to access data within
> classes, or do they access the data directly?

Either directly, or guarded with properties (2.2+).

Older Python versions don't have properties, but you can emulate them by 
overriding __getattr__ and __setattr__ appropriately.

-- Gerhard





More information about the Python-list mailing list