) 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
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
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.
>
>
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
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
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
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
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
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"
>
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
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
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
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
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
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
&
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
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
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
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(
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
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
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
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
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
> >
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
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
> 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
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
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():
>>
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
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.
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):
"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
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
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
>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(
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
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
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
.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
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
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):
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(
43 matches
Mail list logo