Some language proposals.

Michael Hudson mwh at python.net
Fri Feb 27 12:33:59 CET 2004


Jacek Generowicz <jacek.generowicz at cern.ch> writes:

> > import types
> > 
> > class foo(object):
> >     pass
> > 
> > class Callable(object):
> >     def __init__(self): # wonder why this is needed:
> >         self.__name__ = 'Callable'
> >     def __call__(self, ob):
> >         return ob
> >     def __get__(self, ob, cls=None):
> >         return types.UnboundMethodType(self, ob, cls)
> >     
> > foo.inst = Callable()
> > 
> > print foo.inst
> > print foo().inst()
> > 
> > (needs 2.3, for 2.2 use new.instancemethod instead).
> 
> Aha !

Glad to be of service...

> I was doing this stuff way back in 2.2[*], where you get
> 
> >>> print foo.inst
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "<stdin>", line 7, in __get__
> TypeError: cannot create 'instance method' instances
> 
> but it does indeed work in 2.3. Thanks for pointing that out.

This is one of the many little ways -- particularly in the area of
new-style classes -- in which Python 2.3 is just Python 2.2 done
right.

Cheers,
mwh

-- 
  I also feel it essential to note, [...], that Description Logics,
  non-Monotonic Logics, Default Logics and Circumscription Logics 
  can all collectively go suck a cow. Thank you.
              -- http://advogato.org/person/Johnath/diary.html?start=4



More information about the Python-list mailing list