Difference between 'function' and 'method'
castironpi at gmail.com
castironpi at gmail.com
Wed Mar 5 01:21:18 EST 2008
On Mar 4, 10:57 pm, castiro... at gmail.com wrote:
> > > > >> >> Can you overload -type-'s decision of what to 'bind'?... whenever it
> > > > >> >> is it makes it.
>
> > > > >> >>>> from types import FunctionType, MethodType
> > > > >> >>>> class A( FunctionType ): pass
> > > > >> > ...
> > > > >> > Traceback (most recent call last):
> > > > >> > File "<stdin>", line 1, in <module>
> > > > >> > TypeError: type 'function' is not an acceptable base type
>
> > > > >> Use delegation instead of inheritance. This class is almost
> > > > >> indistinguishable from a true function (when used as a method):
> > > If P gets, p gotcha.
> > Notwithstanding. Now bar has a name.
> Now func has it.
>
> from functools import wraps
> class myfunction:
> __slots__ = ('func','name')
> #
> def __init__(self, func):
> @wraps( func )
> def f( *ar, **kws ):
> return func( self, *ar, **kws )
> object.__setattr__(self, 'func', f)
> object.__setattr__(self, 'name', None)
Now:
Where is partialobject.__get__, why is 'attribute "__get__" read-
only', and for self.__get__= func.__get__, why is "'member_descriptor'
object is not callable"?
More information about the Python-list
mailing list