Re: Class: @property -> .__dict__

2011-12-16 Thread Ian Kelly
) if attr != "attributelist" and >            isinstance(getattr(self, attr), numpy.ndarray)] > > to avoid the infinite recursion. Or remove attributelist from the class (it feels more like a generic function than a class property to me) or make it a method instead of a property. -- http://mail.python.org/mailman/listinfo/python-list

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

Class: @property -> .__dict__

2011-12-16 Thread Ulrich
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): return 2 * self.a t = te() In [4]: t.a Out[4]: 23 In [5]: t.b Out[5]: 4

Re: How to use a class property to store function variables?

2010-04-28 Thread Bruno Desthuilliers
GZ a écrit : (snip) Ah, this totally works. The key is to use the staticmethod function. staticmethod is not a function, it's a class. Another question: I am not sure how staticmethod works internally. And the python doc does not seem to say. What does it do? It's easy to figure this out on

Re: How to use a class property to store function variables?

2010-04-28 Thread GZ
On Apr 28, 1:20 am, Chris Rebert wrote: > On Tue, Apr 27, 2010 at 11:02 PM, GZ wrote: > > On Apr 27, 9:20 pm, alex23 wrote: > >> GZ wrote: > >> > I do not think it will help me. I am not trying to define a function > >> > fn() in the class, but rather I want to make it a "function reference" >

Re: How to use a class property to store function variables?

2010-04-27 Thread Chris Rebert
On Tue, Apr 27, 2010 at 11:02 PM, GZ wrote: > On Apr 27, 9:20 pm, alex23 wrote: >> GZ wrote: >> > I do not think it will help me. I am not trying to define a function >> > fn() in the class, but rather I want to make it a "function reference" >> > so that I can initialize it any way I like later

Re: How to use a class property to store function variables?

2010-04-27 Thread GZ
On Apr 27, 9:20 pm, alex23 wrote: > GZ wrote: > > I do not think it will help me. I am not trying to define a function > > fn() in the class, but rather I want to make it a "function reference" > > so that I can initialize it any way I like later. > > It always helps to try an idea out before dis

Re: How to use a class property to store function variables?

2010-04-27 Thread GZ
On Apr 27, 9:20 pm, alex23 wrote: > GZ wrote: > > I do not think it will help me. I am not trying to define a function > > fn() in the class, but rather I want to make it a "function reference" > > so that I can initialize it any way I like later. > > It always helps to try an idea out before dis

Re: How to use a class property to store function variables?

2010-04-27 Thread alex23
GZ wrote: > I do not think it will help me. I am not trying to define a function > fn() in the class, but rather I want to make it a "function reference" > so that I can initialize it any way I like later. It always helps to try an idea out before dismissing it out of hand. Experimentation in the

Re: How to use a class property to store function variables?

2010-04-27 Thread MRAB
Terry Reedy wrote: On 4/27/2010 7:36 PM, GZ wrote: I want to store a reference to a function into a class property. So I am expecting that: class A: fn = lambda x: x fn = A.fn fn(1) Traceback (most recent call last): File "", line 1, in TypeError: unbound method() must

Re: How to use a class property to store function variables?

2010-04-27 Thread GZ
Hi Chris, On Apr 27, 6:43 pm, Chris Rebert wrote: > On Tue, Apr 27, 2010 at 4:36 PM, GZ wrote: > > I want to store a reference to a function into a class property. > > > So I am expecting that: > > > class A: > >     fn = lambda x: x > > > fn = A.fn &

Re: How to use a class property to store function variables?

2010-04-27 Thread Terry Reedy
On 4/27/2010 7:36 PM, GZ wrote: I want to store a reference to a function into a class property. So I am expecting that: class A: fn = lambda x: x fn = A.fn fn(1) Traceback (most recent call last): File "", line 1, in TypeError: unbound method() must be called with A i

Re: How to use a class property to store function variables?

2010-04-27 Thread Chris Rebert
On Tue, Apr 27, 2010 at 4:36 PM, GZ wrote: > I want to store a reference to a function into a class property. > > So I am expecting that: > > class A: >     fn = lambda x: x > > fn = A.fn > fn(1) > > Traceback (most recent call last): >  File "", line

How to use a class property to store function variables?

2010-04-27 Thread GZ
I want to store a reference to a function into a class property. So I am expecting that: class A: fn = lambda x: x fn = A.fn fn(1) Traceback (most recent call last): File "", line 1, in TypeError: unbound method () must be called with A instance as first argument (got in

Re: Yet another question about class property.

2009-05-20 Thread Dave Angel
Jim Qiu wrote: Thanks for you patience, Dave. Obviously i have not got used to the python philosophy. Following you guide, i implemented the following code, and you are absolutely right. #!/usr/bin/python #coding:utf-8 class Parent(object): def __init__(self): pass def displayAttrOfSubClass(

Re: Yet another question about class property.

2009-05-20 Thread Jim Qiu
Thanks for you patience, Dave. Obviously i have not got used to the python philosophy. Following you guide, i implemented the following code, and you are absolutely right. #!/usr/bin/python #coding:utf-8 class Parent(object): def __init__(self): pass def displayAttrOfSubClass(self): print self

Re: Yet another question about class property.

2009-05-20 Thread Dave Angel
Jim Qiu wrote: Hi everyone, Following is the code i am reading, i don't see anywhere the declaration of Message.root object, Where is it from? #bots-modules import bots.botslib as botslib import bots.node as node from bots.botsconfig import * class Message(object): ''' abstract class; rep

Re: Yet another question about class property.

2009-05-20 Thread Mike Kazantsev
Jim Qiu wrote: > Hi everyone, > > Following is the code i am reading, i don't see anywhere the declaration of > Message.root object, > Where is it from? ... Prehaps it gets assigned by the parent itself? Like this: def spawn_child(self): child = Message() child.root = self -- Mike Ka

Yet another question about class property.

2009-05-20 Thread Jim Qiu
Hi everyone, Following is the code i am reading, i don't see anywhere the declaration of Message.root object, Where is it from? #bots-modules import bots.botslib as botslib import bots.node as node from bots.botsconfig import * class Message(object): ''' abstract class; represents a edi mes

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

class property not working in python 2.5.1

2009-02-25 Thread Dan Barbus
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 (string). I have the following

Re: method to create class property

2008-03-19 Thread Diez B. Roggisch
> Isn't that:: > > > > @propset(foo) > > def foo(self, value): > > self._value = value Yeah, you are right. Diez -- http://mail.python.org/mailman/listinfo/python-list

Re: method to create class property

2008-03-18 Thread Alan Isaac
Diez B. Roggisch wrote: > In python 3.0, there will be an even nicer way - propset: > @property > def foo(self): > return self._foo > @propset > def foo(self, value): > self._value = value Isn't that:: @propset(foo) def foo(self, value): self._value = valu

Re: method to create class property

2008-03-18 Thread Diez B. Roggisch
Joe P. Cool schrieb: > On 18 Mrz., 21:59, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: >> Joe P. Cool schrieb: >>> def _property_y(self): >>> def _get(self): >>> [...] >> There are a few recipies, like this: >> >> class Foo(object): >> >> @apply >> def foo(): >>

Re: method to create class property

2008-03-18 Thread Joe P. Cool
On 18 Mrz., 21:59, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Joe P. Cool schrieb: > >     def _property_y(self): > >         def _get(self): > >             [...] > > There are a few recipies, like this: > > class Foo(object): > >     [EMAIL PROTECTED] >      def foo(): >          def fget(se

Re: method to create class property

2008-03-18 Thread Diez B. Roggisch
Joe P. Cool schrieb: > Hi, > > I like C#'s style of defining a property in one place. Can the > following way > to create a property be considered reasonable Python style (without > the > print statements, of course)? > > class sample(object): > def __init__(self): > sample.y = self.

method to create class property

2008-03-18 Thread Joe P. Cool
Hi, I like C#'s style of defining a property in one place. Can the following way to create a property be considered reasonable Python style (without the print statements, of course)? class sample(object): def __init__(self): sample.y = self._property_y() def _property_y(self):

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

Class property with value and class

2006-12-18 Thread manstey
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.name = 'John' ClassA.xx.address = 'Sydn

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(

class property methods getting called only once

2006-12-03 Thread [EMAIL PROTECTED]
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(self,value): ... print 'setting' ... self._color = value ... def _getc

Re: Class property

2005-10-14 Thread Bengt Richter
x" >return cls._x >def set_x(cls,value): >cls._x = value >print "Set %s.x to %s" % (cls.__name__,value) >x = property(get_x,set_x) > >class A(object): >__metaclass__ = MyXMetaClass > >print A.x >A.x = 8 > > >Resu

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
.cnt,A.a_cnt # 1,0 > a = A() > print A.cnt,A.a_cnt # 2,1 > > But then, I may want to create read-only class property that returns the > cnt/a_cnt ratio. > This now cannot be implemented with a metaclass, because the metaclass > cannot operate on the class attributes: Huh? Ever

Re: Class property

2005-10-06 Thread Laszlo Zsolt Nagy
x) class A(object): __metaclass__ = MyXMetaClass print A.x A.x = 8 Results in: Getting x 0 Set A.x to 8 But of course this is bad because the class attribute is not stored in the class. I feel it should be. Suppose we want to create a class property, and a class attribute; and we would like

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):

Class property (was: Class methods)

2005-10-06 Thread Laszlo Zsolt Nagy
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 not. This is what I imagined: class A(object): _x = 0 @classmethod def get_x(