John Posner a écrit :
On 3/22/2010 11:44 AM, Bruno Desthuilliers wrote:
Another (better IMHO) solution is to use a plain property, and store the
computed value as an implementation attribute :
@property
def foo(self):
cached = self.__dict__.get('_foo_cache')
if cached is None:
self._foo_cach
In <4ba79040$0$22397$426a7...@news.free.fr> Bruno Desthuilliers
writes:
>kj a écrit :
>> PS: BTW, this is not the first time that attempting to set an
>> attribute (in a class written by me even) blows up on me. It's
>> situations like these that rattle my grasp of attributes, hence my
>> origi
On 3/22/2010 11:44 AM, Bruno Desthuilliers wrote:
Another (better IMHO) solution is to use a plain property, and store the
computed value as an implementation attribute :
@property
def foo(self):
cached = self.__dict__.get('_foo_cache')
if cached is None:
self._foo_cache = cached = self._some
kj a écrit :
In Dennis Lee Bieber
writes:
On Sun, 21 Mar 2010 16:57:40 + (UTC), kj
declaimed the following in gmane.comp.python.general:
Regarding properties, is there a built-in way to memoize them? For
example, suppose that the value of a property is obtained by parsing
the content
* kj:
In Dennis Lee Bieber
writes:
On Sun, 21 Mar 2010 16:57:40 + (UTC), kj
declaimed the following in gmane.comp.python.general:
Regarding properties, is there a built-in way to memoize them? For
example, suppose that the value of a property is obtained by parsing
the contents of a
In Dennis Lee Bieber
writes:
>On Sun, 21 Mar 2010 16:57:40 + (UTC), kj
>declaimed the following in gmane.comp.python.general:
>> Regarding properties, is there a built-in way to memoize them? For
>> example, suppose that the value of a property is obtained by parsing
>> the contents of a
In <4ba66311$0$27838$c3e8...@news.astraweb.com> Steven D'Aprano
writes:
>Then, in your __init__ method, to initialise an attribute use:
>self.__dict__['attr'] = value
>to bypass the setattr.
Ah, that's the trick! Thanks!
~K
--
http://mail.python.org/mailman/listinfo/python-list
Christian Heimes wrote:
> Steve Holden wrote:
>> You may well find that namedtuple is faster than what you put together
>> yourself, as the collections module is implemented in C.
>
> But namedtuple isn't, Steve. Namedtuple is a class generator that
> creates fast and efficient classes.
>
Ah, rig
On Mar 21, 11:57 am, kj wrote:
>
> Just accessing attributes looks a bit dangerous to me, due to bugs
> like typing
>
> i.typo = 'foo'
>
> when what you meant is
>
> i.type = 'foo'
>
> I tried fixing this by mucking with __setattr__, but I didn't hit
> on a satisfactory solution (basically, I
Steve Holden wrote:
> You may well find that namedtuple is faster than what you put together
> yourself, as the collections module is implemented in C.
But namedtuple isn't, Steve. Namedtuple is a class generator that
creates fast and efficient classes.
--
http://mail.python.org/mailman/listinfo
On Sun, 21 Mar 2010 16:57:40 +, kj wrote:
> Just accessing attributes looks a bit dangerous to me, due to bugs like
> typing
>
> i.typo = 'foo'
>
> when what you meant is
>
> i.type = 'foo'
That's the price you pay for using a dynamic language like Python with no
declarations. But hon
In <4ba58503$0$27838$c3e8...@news.astraweb.com> Steven D'Aprano
writes:
>On Sat, 20 Mar 2010 22:15:54 +, kj wrote:
>> I need to create a class solely for the purpose of encapsulating a large
>> number of disparate data items.
>There's a built-in for that. It's called "dict". Syntax for ite
kj wrote:
> In Chris Rebert
> writes:
>
>> On Sat, Mar 20, 2010 at 3:15 PM, kj wrote:
>>> I need to create a class solely for the purpose of encapsulating
>>> a large number of disparate data items. =C2=A0At the moment I have no
>>> plans for any methods for this class other than the bazillion
In Chris Rebert
writes:
>On Sat, Mar 20, 2010 at 3:15 PM, kj wrote:
>> I need to create a class solely for the purpose of encapsulating
>> a large number of disparate data items. =C2=A0At the moment I have no
>> plans for any methods for this class other than the bazillion
>> accessors require
In <639908184290880449.447600deets-nospam.web...@news.hansenet.de> Diez B.
Roggisch writes:
>You don't. Python is not Java. So just use instance attributes, and if
>you need bhavior when accessing an attribute, introduce a property.
Just accessing attributes looks a bit dangerous to me, due t
kj wrote:
>
>
>
>
>
>
> I need to create a class solely for the purpose of encapsulating
> a large number of disparate data items. At the moment I have no
> plans for any methods for this class other than the bazillion
> accessors required to access these various instance variables.
> (In c
On Sat, 20 Mar 2010 22:15:54 +, kj wrote:
> I need to create a class solely for the purpose of encapsulating a large
> number of disparate data items.
There's a built-in for that. It's called "dict". Syntax for item access
is a tiny bit different, but still very common:
data['foo']
instead
Just initialize everything in the constructor, unless you have *really *good
reason not to do that.
On Sat, Mar 20, 2010 at 6:54 PM, Chris Rebert wrote:
> On Sat, Mar 20, 2010 at 3:15 PM, kj wrote:
> > I need to create a class solely for the purpose of encapsulating
> > a large number of dispara
On Sat, Mar 20, 2010 at 3:15 PM, kj wrote:
> I need to create a class solely for the purpose of encapsulating
> a large number of disparate data items. At the moment I have no
> plans for any methods for this class other than the bazillion
> accessors required to access these various instance var
I need to create a class solely for the purpose of encapsulating
a large number of disparate data items. At the moment I have no
plans for any methods for this class other than the bazillion
accessors required to access these various instance variables.
(In case it matters, this class is mea
20 matches
Mail list logo