I know that if I write a class, I can definite a custom print function as below.
>>> class F:
... def __str__(self):
... return 'This describes the data of F.'
...
>>> f = F()
>>> print f
This describes the data of F.
But, what if I want to do the same for a function object? For example,
>>> def f():
... pass
...
>>> g = f
>>> print g
<function f at 0x7f738d6da5f0>
Instead of '<function f at 0x7f738d6da5f0>', I'd like to somehow specify what was printed. The motivation for doing this is that I'm going to store a bunch of function objects in a list, and I'd like to iterate over the list and print human-readable descriptions of the types of functions without adding additional complexity, e.g., tuples of function objects and strings.
Thanks in advance for any help you can provide.
Edit: I changed my example to reflect what I was trying to convey, unfortunately I typed 'f()' when I meant 'f'. I am interested in a custom label for the function object, not customizing the return (which it is obvious how to do). Sorry for any confusion this has caused.
gis the return value off. Are you storing functions in the list, or their return values?__repr__and__str__special methods of a function object seems to do nothing. It's surprising that Python doesn't allow these to be overridden while not also raising an error which it does, for example, if you try to override the__repr__method of alistobject.__repr__rather than the object's__repr__. So it uses<type 'function'>'s__repr__, notsomefunc's__repr__