Functions attributes accessed from within the function definition URGENT please

Alex Martelli aleaxit at
Wed May 30 11:11:09 EDT 2001

"dsavitsk" <dsavitsk at> wrote in message
news:Uk7R6.1617$6t.1421996 at
> is this what you are after?
> def f(x=31426):
>     pass

I think this would be an ARGUMENT, while Fernando is
asking about an ATTRIBUTE:

> "Fernando Rodríguez" <spamers at must.die> wrote in message
> news:o70aht0nl21e323pfkmgj0p6sabhm7q6f3 at
> > 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

and then the answer is, e.g.:

def f(whatever):
    return 3*f.x
f.x = 31426

I.e., set f's attributes with normal syntax just AFTER the
def statement that binds the name f to the function object.


More information about the Python-list mailing list