adding attributes to a function, from within the function
mis6 at pitt.edu
Mon Nov 3 18:04:29 CET 2003
Fernando Rodriguez <frr at easyjob.net> wrote in message news:<as15qvs0nna5mvio4agd5su99fmrcgui4e at 4ax.com>...
> I'd like to do something like this:
> def fn():
> error = "Error message"
> return 1
> print fn.error
You can always use a closure:
def _(): return 1
However, IMHO using a class is better since automatic
documentation tools and inspection features work better for classes
than for closures.
More information about the Python-list