Tcl style traces

Andrew Bennetts andrew-pythonlist at puzzling.org
Wed Jan 28 01:21:35 EST 2004


On Wed, Jan 28, 2004 at 10:18:59AM +0800, Derek Fountain wrote:
> Does Python have something similar to Tcl style tracing? That is, the
> ability to call a subroutine when a variable is written to or read from?

Not for variables in general, unless you feel like mucking about with
sys.settrace.

For attributes of objects, you can use __getattr__/__setattr__ methods, use
__getattribute__/__setattribute__ methods, use properties, or even
roll-your-own descriptor, depending on what you need.

What do you need this for?  If you can be more specific, we might be able to
help you a little better.

-Andrew.





More information about the Python-list mailing list