What is a mechanism equivalent to "trace variable w ..." in Tcl for Python?
Ned Batchelder
ned at nedbatchelder.com
Fri Sep 30 14:42:49 EDT 2016
On Friday, September 30, 2016 at 2:16:10 PM UTC-4, Les Cargill wrote:
> A really interesting design approach in Tcl is to install a callback
> when a variable is written to. This affords highly event-driven
> programming.
>
> Example ( sorry; it's Tcl ) :
>
>
(I can't read Tcl, sorry)
>
> What is an equivalent mechanism in Python?
There's no way* to hook into "x = 2", but you could hook into "x.a = 2"
if you wanted do, by defining __setattr__ on x's class.
*OK, there might be some crazy hack involving your own class as the
globals for a module or something, but it sounds ill-advised.
--Ned.
More information about the Python-list
mailing list