On 21 August 2012 16:19, Oscar Benjamin wrote:
>
> On Aug 21, 2012 3:42 PM, "Massimo DiPierro"
> wrote:
> >
> > Thanks again Oscar. I cannot do that. I have tight constraints. I am not
> at liberty to modify the code that uses the class. The exposed API cannot
> change including a.x, dict(a), is
Thanks again Oscar. I cannot do that. I have tight constraints. I am not at
liberty to modify the code that uses the class. The exposed API cannot change
including a.x, dict(a), is isinstance(a,dict).
My goal it so change the definition of this class to make it faster.
Where is in the Python so
On 21 August 2012 14:50, Massimo Di Pierro wrote:
> Hello Oscar,
>
> thanks for your help but your proposal of adding:
>
> def __setitem__(self,key,value):
>self.__dict__[key] = value
>dict.__setitem__(self, key, value)
>
> does not help me.
>
> What I have today is a class that works like
Hello Oscar,
thanks for your help but your proposal of adding:
def __setitem__(self,key,value):
self.__dict__[key] = value
dict.__setitem__(self, key, value)
does not help me.
What I have today is a class that works like SlowStorage. I want to
replace it with NewStorage because it is 10x
On 21 August 2012 13:52, Massimo Di Pierro wrote:
> On Aug 21, 2:40 am, Oscar Benjamin wrote:
> > On Mon, 20 Aug 2012 21:17:15 -0700 (PDT), Massimo Di Pierro
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > wrote:
> > > Consider this code:
> > > class SlowStorage(dict):
> > > def __getattr__(self,key
On Aug 21, 2:40 am, Oscar Benjamin wrote:
> On Mon, 20 Aug 2012 21:17:15 -0700 (PDT), Massimo Di Pierro
>
>
>
>
>
>
>
>
>
> wrote:
> > Consider this code:
> > class SlowStorage(dict):
> > def __getattr__(self,key):
> > return self[key]
> > def __setattr__(self,key):
> >
On Mon, 20 Aug 2012 21:17:15 -0700 (PDT), Massimo Di Pierro
wrote:
Consider this code:
class SlowStorage(dict):
def __getattr__(self,key):
return self[key]
def __setattr__(self,key):
self[key]=value
class FastStorage(dict):
def __init__(self, __d__=None, *
Consider this code:
class SlowStorage(dict):
def __getattr__(self,key):
return self[key]
def __setattr__(self,key):
self[key]=value
class FastStorage(dict):
def __init__(self, __d__=None, **kwargs):
self.update(__d__,**kwargs)
def __getitem__(self,key):
The fact is this works:
>>> class B(object):
...__class__ = dict
>>> b=B()
but this does not
>>> class B(object):
...def __init__(self):
...self.__class__ = dict
>>> b=B()
Traceback (most recent call last):
File "", line 1, in
File "", line 3, in __init__
TypeError: __class_
On Mon, Aug 20, 2012 at 12:01 PM, Massimo Di Pierro
wrote:
> I discovered I can do this:
>
> class A(object): pass
> class B(object):
> __class__ = A # magic
>
> b = B()
> isinstance(b,A) # returns True (as if B derived from A)
> isinstance(b,B) # also returns True
On Mon, 20 Aug 2012 11:01:36 -0700, Massimo Di Pierro wrote:
> I discovered I can do this:
>
> class A(object): pass
> class B(object):
> __class__ = A # magic
Why do you think that's magic?
> b = B()
> isinstance(b,A) # returns True (as if B derived from A)
b.__
I discovered I can do this:
class A(object): pass
class B(object):
__class__ = A # magic
b = B()
isinstance(b,A) # returns True (as if B derived from A)
isinstance(b,B) # also returns True
I have some reasons I may want to do this (I an object with same
methods a
12 matches
Mail list logo