Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!newsfeed.tele2net.at!news.panservice.it!feed.xsnews.nl!border02.ams.xsnews.nl!feeder04.ams.xsnews.nl!abp002.ams.xsnews.nl!frontend-F10-14.ams.news.kpn.nl From: Cecil Westerhof Newsgroups: comp.lang.python Subject: Re: Not possible to hide local variables Organization: Decebal Computing References: <874mo0zoz2.fsf@Equus.decebal.nl> X-Face: "(y8cC@tg_12{">GF'UXTW]FHI2wMiZNrnf'1EFQ&O#$m:f#O7+7}kR,v+Pti8=Vi/Z"g^?b"E X-Homepage: http://www.decebal.nl/ Date: Wed, 29 Apr 2015 08:14:33 +0200 Message-ID: <87twvzxxyu.fsf@Equus.decebal.nl> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:siUkR86BRnhXsBUluXvWNu2pXBQ= MIME-Version: 1.0 Content-Type: text/plain Lines: 26 NNTP-Posting-Host: 81.207.62.244 X-Trace: 1430289871 news.kpn.nl 21156 81.207.62.244@kpn/81.207.62.244:33271 Xref: csiph.com comp.lang.python:89520 Op Tuesday 28 Apr 2015 09:33 CEST schreef Cecil Westerhof: > 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? I have posted it on: https://github.com/CecilWesterhof/PythonLibrary/blob/master/utilDecebal.py -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof