Re: Not possible to hide local variables

2015-04-30 Thread Cecil Westerhof
Op Thursday 30 Apr 2015 14:53 CEST schreef Dennis Lee Bieber: > On Wed, 29 Apr 2015 22:31:13 -0400, Dave Angel > declaimed the following: > >> On 04/29/2015 10:16 AM, Grant Edwards wrote: > >> >>> raise ParameterError, 'Parameter has to be an int' >>> if n < 0: >> >> Better: if length < 0:

Re: Not possible to hide local variables

2015-04-29 Thread Chris Angelico
On Thu, Apr 30, 2015 at 3:10 PM, Marko Rauhamaa wrote: > Steven D'Aprano : > >> If you have a Java background, you might find this useful: >> >> http://dirtsimple.org/2004/12/python-is-not-java.html >> >> http://dirtsimple.org/2004/12/java-is-not-python-either.html > > Unfortunately, I didn't find

Re: Not possible to hide local variables

2015-04-29 Thread Marko Rauhamaa
Steven D'Aprano : > If you have a Java background, you might find this useful: > > http://dirtsimple.org/2004/12/python-is-not-java.html > > http://dirtsimple.org/2004/12/java-is-not-python-either.html Unfortunately, I didn't find those articles all that insightful. The one big difference betwee

Re: Not possible to hide local variables

2015-04-29 Thread Steven D'Aprano
On Wednesday 29 April 2015 16:32, Cecil Westerhof wrote: >> The convention is, if the caller messes with your private attributes >> or variables, and their code breaks, they have nobody to blame but >> themselves, and we are allowed to laugh at them. We're consenting >> adults here. > > Coming fr

Re: Not possible to hide local variables

2015-04-29 Thread Michael Torrie
On 04/29/2015 12:16 AM, Cecil Westerhof wrote: >> Prefix those names with a single leading underscore, which is the >> convention for private variables. > > Done. > >> This way, if some user (maybe you! ;) has a good reason to change >> those values in can be done, but it is quite clear that said

Re: Not possible to hide local variables

2015-04-29 Thread Dave Angel
On 04/29/2015 10:16 AM, Grant Edwards wrote: On 2015-04-28, Cecil Westerhof wrote: 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:

Re: Not possible to hide local variables

2015-04-29 Thread Grant Edwards
On 2015-04-28, Cecil Westerhof wrote: > 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, 'P

Re: Not possible to hide local variables

2015-04-29 Thread Chris Angelico
On Wed, Apr 29, 2015 at 4:25 PM, Cecil Westerhof wrote: > Op Tuesday 28 Apr 2015 10:06 CEST schreef Chris Angelico: >> (note that I'm avoiding the multiple-argument syntax which doesn't >> work in Python 3; > > I already did this with print. Are there other statements I have to > take care for the

Re: Not possible to hide local variables

2015-04-29 Thread Cecil Westerhof
Op Tuesday 28 Apr 2015 10:37 CEST schreef Steven D'Aprano: > On Tuesday 28 April 2015 17:33, Cecil Westerhof wrote: > >> If I remember correctly you can not hide variables of a class or >> make them read-only? > > In Python circles, the preferred terminology for class and instance > members is "at

Re: Not possible to hide local variables

2015-04-28 Thread Cecil Westerhof
Op Tuesday 28 Apr 2015 10:06 CEST schreef Chris Angelico: > In fact, it's not really your problem if someone gives you a length > that isn't a simple integer. In the first place, they might give you > a subclass of int, so a better check would be this: > > if not isinstance(length, int): > raise V

Re: Not possible to hide local variables

2015-04-28 Thread Cecil Westerhof
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, 'Para

Re: Not possible to hide local variables

2015-04-28 Thread Cecil Westerhof
Op Tuesday 28 Apr 2015 09:56 CEST schreef Ethan Furman: > On 04/28, Cecil Westerhof wrote: >> 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)

Re: Not possible to hide local variables

2015-04-28 Thread Marko Rauhamaa
Steven D'Aprano : > The convention is, if the caller messes with your private attributes > or variables, and their code breaks, they have nobody to blame but > themselves, and we are allowed to laugh at them. We're consenting > adults here. I would take it further: as a rule, user code should not

Re: Not possible to hide local variables

2015-04-28 Thread Chris Angelico
On Tue, Apr 28, 2015 at 6:37 PM, Steven D'Aprano wrote: > The convention is, if the caller messes with your private attributes or > variables, and their code breaks, they have nobody to blame but themselves, > and we are allowed to laugh at them. We're consenting adults here. > > (The only excepti

Re: Not possible to hide local variables

2015-04-28 Thread Steven D'Aprano
On Tuesday 28 April 2015 17:33, Cecil Westerhof wrote: > If I remember correctly you can not hide variables of a class or make > them read-only? In Python circles, the preferred terminology for class and instance members is "attributes" rather than variables. "Variable" is reserved for module-

Re: Not possible to hide local variables

2015-04-28 Thread Chris Angelico
On Tue, Apr 28, 2015 at 5:33 PM, Cecil Westerhof wrote: > 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

Re: Not possible to hide local variables

2015-04-28 Thread Ethan Furman
On 04/28, Cecil Westerhof wrote: > 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, 'Parame

Not possible to hide local variables

2015-04-28 Thread 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: