adding attributes to a function, from within the function
Shu-Hsien Sheu
sheu at bu.edu
Fri Oct 31 12:00:03 EST 2003
Hi,
I think you would need to use a class rather than function.
>>> class fn(object):
def __init__(self):
self.error = 'Error message'
>>> kk = fn()
>>> kk.error
'Error message'
-shuhsien
>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