[Tutor] C-like local static var in Py ?
Yann Le Du
yann.ledu@noos.fr
Sun Dec 1 21:56:00 2002
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
> >You can reset this by setting v=[0] outside of that function.
>
> No; that does not work. This creates a global variable v that is
> independent of the one in inc. However this will work:
>
> v2 = [0]
> def inc(v = v2):
> # rest the same
Yes, you're right ! I went too fast... I thought I had understood, and had
not.
>
> You can then reset things by resetting v2[0]. Note that if you set v2 = 0
> you create a new list assigned to v2; the original list still remains
> associated with the function default.
Yes, amazing : v2[0]=0 is not the same as v2=[0].
> If one adds print id(v) to inc one sees, as expected, the same number
> (address of the object) each time. Is there some way in Python, given such
> an id, to access the object at that address?
I have no idea...
Y
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: For info see http://quantumlab.net/pine_privacy_guard/
iD8DBQE96suQt4mG++uo5yQRAsomAJ4lmSaOZxX3PP66oHD7hBlR9wcbqQCfQvyl
lEe7Og/+KOZo00YVSGN9aTU=
=1puk
-----END PGP SIGNATURE-----