Steven D'Aprano wrote:
def SomeClass(object):
_gridsize = 0.8
The leading underscore tells callers that they change the attribute at
their own risk.
An even more Pythonic approach is to write your class that makes no
assumptions about gridsize, and thus explicitly supports any reaso
On Mon, 25 Aug 2008 19:47:38 +0100, Ken Starks wrote:
> I have a class with an attribute called 'gridsize' and I want a derived
> class to force and keep it at 0.8 (representing 8mm).
>
> Is this a correct, or the most pythonic approach?
Others have already suggested using a property, but I'll s
Marc 'BlackJack' Rintsch wrote:
On Mon, 25 Aug 2008 21:44:49 +0100, Ken Starks wrote:
def __getattr__(self,attrname):
if attrname == 'gridsize':
return 0.8
def __setattr__(self,attrname,value):
if attrname == 'gridsize':
On Mon, 25 Aug 2008 21:44:49 +0100, Ken Starks wrote:
>>>
>>>
>>> def __getattr__(self,attrname):
>>> if attrname == 'gridsize':
>>> return 0.8
>>>
>>> def __setattr__(self,attrname,value):
>>> if attrname == 'gridsize':
>>>
André wrote:
On Aug 25, 3:47 pm, Ken Starks <[EMAIL PROTECTED]> wrote:
I have a class with an attribute called 'gridsize' and I want
a derived class to force and keep it at 0.8 (representing 8mm).
Is this a correct, or the most pythonic approach?
def __getattr__(self
On Aug 25, 3:47 pm, Ken Starks <[EMAIL PROTECTED]> wrote:
> I have a class with an attribute called 'gridsize' and I want
> a derived class to force and keep it at 0.8 (representing 8mm).
>
> Is this a correct, or the most pythonic approach?
>
>
>
> def __getattr__(self,at
On Aug 25, 2:09 pm, Ken Starks <[EMAIL PROTECTED]> wrote:
> Ken Starks wrote:
> > I have a class with an attribute called 'gridsize' and I want
> > a derived class to force and keep it at 0.8 (representing 8mm).
>
> > Is this a correct, or the most pythonic approach?
>
> >
>
>
Ken Starks wrote:
I have a class with an attribute called 'gridsize' and I want
a derived class to force and keep it at 0.8 (representing 8mm).
Is this a correct, or the most pythonic approach?
def __getattr__(self,attrname):
if attrname == 'gridsize':