adding attributes to builtin functions
Peter Hansen
peter at engcorp.com
Mon Jun 24 21:58:33 EDT 2002
Douglas Zongker wrote:
>
> import mymodule
> print mymodule.myfunction
> mymodule.myfunction.special = 6
>
> gives me:
>
> <built-in function myfunction>
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> TypeError: 'builtin_function_or_method' object has only read-only
> attributes (assign to .special)
>
> Is there a way to define a builtin function whose attributes aren't
> read-only?
Maybe something like this?
import mymodule
def myfunction(*argp, **argn):
return mymodule.myfunction(*argp, **argn)
mymodule.myfunction = myfunction
mymodule.myfunction.special = 6
Tada! (Actually, I have *no* idea if this works. :-)
-Peter
More information about the Python-list
mailing list