Re: Class: @property -> .__dict__

2011-12-16 Thread Ian Kelly
On Fri, Dec 16, 2011 at 2:32 AM, Peter Otten <__pete...@web.de> wrote: > Ulrich wrote: > >> if I replace it to >> def attributelist(self): >>          # find all attributes to the class that are of type numpy >> arrays: >>          return [attr for attr in dir(self) if >> isinstance(getattr(self, a

Re: Class: @property -> .__dict__

2011-12-16 Thread Thomas Rachel
Am 16.12.2011 09:52 schrieb Ulrich: Could anyone please explain me why this does not work / how to get b into .__dict__ / hint me to an explanation? b is not a data element of the particular instance, but it lives in the class. It is, roughly spoken, a "kind of method", just to be used witho

Re: Class: @property -> .__dict__

2011-12-16 Thread Peter Otten
Ulrich wrote: > if I replace it to > def attributelist(self): > # find all attributes to the class that are of type numpy > arrays: > return [attr for attr in dir(self) if > isinstance(getattr(self, attr), numpy.ndarray)] > > it crashes going into some kind of endless loop. > >

Re: Class: @property -> .__dict__

2011-12-16 Thread Ulrich
On Dec 16, 10:11 am, Ulrich wrote: > On Dec 16, 10:03 am, Steven D'Aprano > > > > > > > > > +comp.lang.pyt...@pearwood.info> wrote: > > On Fri, 16 Dec 2011 00:52:11 -0800, Ulrich wrote: > > > Good morning, > > > > I wonder if someone could please help me out with the @property function > > > as i

Re: Class: @property -> .__dict__

2011-12-16 Thread Ulrich
On Dec 16, 10:03 am, Steven D'Aprano wrote: > On Fri, 16 Dec 2011 00:52:11 -0800, Ulrich wrote: > > Good morning, > > > I wonder if someone could please help me out with the @property function > > as illustrated in the following example. > > > class te(): > >     def __init__(self): > >         se

Re: Class: @property -> .__dict__

2011-12-16 Thread Steven D'Aprano
On Fri, 16 Dec 2011 00:52:11 -0800, Ulrich wrote: > Good morning, > > I wonder if someone could please help me out with the @property function > as illustrated in the following example. > > class te(): > def __init__(self): > self.a = 23 > @property > def b(self): > r

Re: class property not working in python 2.5.1

2009-02-26 Thread utnapistim
On Feb 26, 9:56 am, Christian Heimes wrote: > Dan Barbus schrieb: > > > Hi, > > > I have a problem with setting a property to a class instance, in > > python 2.5.1. The property is defined through get and set methods, but > > when I set it, the setter doesn't get called. Instead, I believe the > >

Re: class property not working in python 2.5.1

2009-02-25 Thread Christian Heimes
Dan Barbus schrieb: > Hi, > > I have a problem with setting a property to a class instance, in > python 2.5.1. The property is defined through get and set methods, but > when I set it, the setter doesn't get called. Instead, I believe the > property in the instance gets replaced with a new object

Re: Class property with value and class

2006-12-19 Thread Ben Finney
"manstey" <[EMAIL PROTECTED]> writes: > Is is possible to have two classes, ClassA and ClassB, and > setattr(ClassA, 'xx',ClassB), AND to then have ClassA.xx store an > integer value as well, which is not part of ClassB? You seem somewhat confused over classes and instances. There's little need t

Re: Class property with value and class

2006-12-19 Thread Diez B. Roggisch
manstey wrote: > Hi, > > Is is possible to have two classes, ClassA and ClassB, and > setattr(ClassA, 'xx',ClassB), AND to then have ClassA.xx store an > integer value as well, which is not part of ClassB? > > e.g. If ClassB has two properties, name and address: > > ClassA.xx=10 > ClassA.xx.nam

Re: class property methods getting called only once

2006-12-03 Thread limodou
>On 3 Dec 2006 21:24:03 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > In the following code, I could not find out why the set and get methods > are not called once I set the property. > > > >>> class Test: > ... def __init__(self): > ... self._color = 12 > ... def _setcolor(

Re: Class property

2005-10-14 Thread Bengt Richter
On Thu, 06 Oct 2005 16:09:22 +0200, Laszlo Zsolt Nagy <[EMAIL PROTECTED]> wrote: >Peter Otten wrote: > >>Laszlo Zsolt Nagy wrote: >> >> >> >>>I was trying for a while, but I could not implement a 'classproperty' >>>function. Is it possible at all? >>> >>> >> >>You could define a "normal" pro

Re: Class property (was: Class methods)

2005-10-14 Thread Bengt Richter
On Thu, 06 Oct 2005 11:05:10 +0200, Laszlo Zsolt Nagy <[EMAIL PROTECTED]> wrote: >Hughes, Chad O wrote: > >> Is there any way to create a class method? I can create a class >> variable like this: >> >Hmm, seeing this post, I have decided to implement a 'classproperty' >descriptor. >But I could

Re: Class property

2005-10-11 Thread Steven Bethard
Laszlo Zsolt Nagy wrote: > class A(object): >cnt = 0 >a_cnt = 0 >def __init__(self): >A.cnt += 1 >if self.__class__ is A: >A.a_cnt += 1 > class B(A): >pass > print A.cnt,A.a_cnt # 0,0 > b = B() > print A.cnt,A.a_cnt # 1,0 > a = A() > print A.c

Re: Class property

2005-10-06 Thread Laszlo Zsolt Nagy
Peter Otten wrote: >Laszlo Zsolt Nagy wrote: > > > >>I was trying for a while, but I could not implement a 'classproperty' >>function. Is it possible at all? >> >> > >You could define a "normal" property in the metaclass: > > The only way I could do this is: class MyXMetaClass(type):

Re: Class property (was: Class methods)

2005-10-06 Thread Peter Otten
Laszlo Zsolt Nagy wrote: > I was trying for a while, but I could not implement a 'classproperty' > function. Is it possible at all? You could define a "normal" property in the metaclass: > class A: ... class __metaclass__(type): ... @property ... def clsprp(cls):