> Another approach would be to stuff the static values in the function's
> __dict__.

That's how I did it when I wanted something similar.

I created this decorator:


def static(**kw):
    '''
    Used to create a decorator function that will add an
    attribute to a function and initialize it.

   >>> @static(foo=5)
    ... def bar():
    ...     print bar.foo
    ...     bar.foo += 1
    ...
   >>> bar()
    5
   >>> bar()
    6
    '''

    def decorator(f):
        f.__dict__.update(kw)
        return f
    return decorator

                                          
_________________________________________________________________
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
https://signup.live.com/signup.aspx?id=60969
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to