use member functions to access data in Python classes?

Peter Hansen peter at
Wed Jun 18 18:45:39 CEST 2003

beliavsky at 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?

I follow the conventional approach used even by the Python libraries,
which have proven to be quite effective :-), by just accessing most
data directly.

If the type of access involved is more complicated that getting or 
setting, I naturally provide a method to perform the operation 

Note that the latest versions of Python have "properties" which will
allow you to combine the best (?) of both worlds by writing code as
though it had direct access but which actually calls methods under
the table.


More information about the Python-list mailing list