[Python-Dev] Re: A syntax for function attributes?

Pat Miller patmiller@llnl.gov
Thu, 31 Jul 2003 16:34:25 -0700


Mark writes:

> def heres_my_function_name(args):
>    heres_my_function_name.my_attribute = "Foo"
> 
> Without a special syntax, I think we'll see more and more abuses of __doc__, like
> 
> def heres_my_function_name(args):
>    """my_attribute = "Foo" """ 

Worse than just being yucky, it is also dangerous to count on
a function keeping the same name or being available in
its context.  Another argument for keeping the sytax
tightly bound to the declaration.

def heres_my_function_name(args):
     heres_my_function_name.my_attribute = "Foo"

callbacks = [ heres_my_function_name, something_else, and_some_more]
del heres_my_function_name

Now, heres_my_function_name fails because the name "heres_my_function_name"
is no longer in the global space.

I actually do sometimes overwrite functions (e.g. replacing a generic
function with a specialized one).





-- 
Patrick Miller | (925) 423-0309 | http://www.llnl.gov/CASC/people/pmiller

I don't want yes men around me. I want everyone to tell
the truth, even if it costs them their jobs.  -- Samuel Goldwyn