On 19 avr, 19:39, sturlamolden <[EMAIL PROTECTED]> wrote: > On Apr 17, 4:06 pm, AlFire <[EMAIL PROTECTED]> wrote: > > > Q: why function got dictionary? What it is used for? > > As previously mentioned, a function has a __dict__ like (most) other > objects. > > You can e.g. use it to create static variables: > > int foobar() > { > static int i = 0; > return i++; > > } > > is roughly equivalent to: > > def foobar(): > foobar.i += 1 > return foobar.i > foobar.i = 0
barfoo = foobar foobar = lambda x : x And boom. 'static' variables are better implemented using either closures, mutable default arguments or custom callable types. -- http://mail.python.org/mailman/listinfo/python-list