[Tutor] C-like local static var in Py ?

Kalle Svensson kalle@lysator.liu.se
Sun Dec 1 22:44:01 2002


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[Bob Gailer]
> 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?

Yes and no.  Officially, there is no way.  There are, however, hacks
that may or may not work.  For example, there is sys.makeref from
mxTools (http://www.egenix.com/files/python/mxTools.html).  Do note
the warnings on that page:

"""
USE WITH CARE: this is an expert-only function since it can cause
instant core dumps and many other strange things -- even ruin your
system if you don't know what you're doing !

SECURITY WARNING: This function can provide you with access to objects
that are otherwise not visible, e.g. in restricted mode, and thus be a
potential security hole.
"""

I wouldn't use it in any code I cared about, but it's a cool hack.

Peace,
  Kalle
- -- 
Kalle Svensson, http://www.juckapan.org/~kalle/
Student, root and saint in the Church of Emacs.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>

iD8DBQE96tbydNeA1787sd0RAlePAJ43qBfpkbIw1TAFFkX8HnT82OqQGQCgg/Vi
hLB9aFhYQnEq7SBoYLTuua0=
=tO89
-----END PGP SIGNATURE-----