why memoizing is faster

Andrea Crotti andrea.crotti.0 at gmail.com
Fri Mar 25 06:53:48 EDT 2011


"eryksun ()" <eryksun at gmail.com> writes:

>
> Regarding this I have question about function attributes. Is there an
> equivalent of 'self' for functions? I've seen people use function
> attributes as local static variables, but this seems problematic when
> all you have is a global reference to the function. The original
> reference might get deleted. Then when your function tries to
> reference its 'static' variable you'll get a NameError exception. For
> example:
>
> In [1]: def test1(n):
>    ...:     test1.a = n
>
> In [2]: test1(10); test1.a
> Out[2]: 10
>
> In [3]: test2 = test1; test2.a
> Out[3]: 10
>

[...]

I had never seen such a thing, but why would this make sense at all?
When does it make sense logically for a function to have an attribute?

A function should have some input, some local variables to compute
temporary results and a return value, I think nothing more...



More information about the Python-list mailing list