adding attributes to builtin functions

Douglas Zongker dougz at cs.washington.edu
Mon Jun 24 18:57:06 EDT 2002


I know that when you def a function in Python you can add arbitrary
attributes to it:

   def foo():
      return 4
   foo.special = 6

Is it possible to do this with a function that comes from a C
extension module?

   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?

thanks,
dz

   




More information about the Python-list mailing list