Not possible to hide local variables

Cecil Westerhof Cecil at
Tue Apr 28 09:33:37 CEST 2015

If I remember correctly you can not hide variables of a class or make
them read-only?

I want to rewrite my moving average to python. The init is:
    def __init__(self, length):
        if type(length) != int:
            raise ParameterError, 'Parameter has to be an int'
        if n < 0:
            raise ValueError, 'Parameter should be greater or equal 2'
        self.length             = length
        self.old_values         = []
        self.current_total      = 0

But when someone changes length, old_values, or current_total that
would wreck havoc with my class instance. What is the best way to
handle this?

Cecil Westerhof
Senior Software Engineer

More information about the Python-list mailing list