Re: Private attribute

2008-08-26 Thread Ken Starks
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

Re: Private attribute

2008-08-25 Thread Steven D'Aprano
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

Re: Private attribute

2008-08-25 Thread Ken Starks
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':

Re: Private attribute

2008-08-25 Thread Marc 'BlackJack' Rintsch
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': >>>

Re: Private attribute

2008-08-25 Thread Ken Starks
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

Re: Private attribute

2008-08-25 Thread André
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

Re: Private attribute

2008-08-25 Thread castironpi
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? > > > > >

Re: Private attribute

2008-08-25 Thread Ken Starks
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':