adding attributes to a function, from within the function

Fernando Rodriguez frr at easyjob.net
Fri Oct 31 11:05:21 EST 2003


Hi,

What's the syntax to add an attribute to a function form the function body?

For example, instead of doing:
def fn():
   return 1
fn.error = "Error message"
print fn.error


I'd like to do something like this:

def fn():
  error = "Error message"
  return 1

print fn.error

How can I do this? O:-)

TIA




More information about the Python-list mailing list