On Friday, September 30, 2016 at 7:16:10 PM UTC+1, 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  ) :
> 
> 
> namespace eval events {
>       set preRPM -1
>       proc handleRPM { args } {
>               # do stuff to handle an RPM change here
>               variable ::motor::RPM
>                  variable preRPM
>               puts "RPM changed from $preRPM to $RPM
>               set preRPM $RPM
>          }
> }
> 
> ...
> 
> trace variable ::motor::RPM w ::events::handleRPM
> 
> ...
> 
> set ::motor::RPM 33.33
> 
> What is an equivalent mechanism in Python?
> 
> Thanks in advance.
> 
> -- 
> Les Cargill

Perhaps you could pinch the idea, or even the code, from tkinter?  E.g. see the 
section "Variable tracing" at 
http://stupidpythonideas.blogspot.co.uk/2013/12/tkinter-validation.html

Kindest regards.

Mark Lawrence.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to