Functions attributes accessed from within the function definition URGENT please

Fredrik Aronsson d98aron at dtek.chalmers.se
Wed May 30 18:04:48 CEST 2001


In article <o70aht0nl21e323pfkmgj0p6sabhm7q6f3 at 4ax.com>,
	Fernando Rodríguez <spamers at must.die> writes:
> Hi!
> 
> 	I have a function f that will have an attribute x: f.x = 31426 (for
> example).
> 
> 	When defining the function f, I'd like to give this attribute a
> default value, so I'll never get an error when trying to access it with f.x,
> how can I do this (setting the default value)? O:-)
> 

Well, why not put the f.x = 31426 right after the definition?
>>> def f():
...   print f.x
... 
>>> f.x=31426
>>> f()
31426

/Fredrik



More information about the Python-list mailing list