473,473 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Tcl style traces

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?
Jul 18 '05 #1
8 1386
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?


No. However, sys.settrace might come close.

Regards,
Martin

Jul 18 '05 #2
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.
Jul 18 '05 #3
Hello Derek,
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 that I know of.

The only way I can think you'll be able to pull this one is by using
pdb.
Just set breakpoints where the variable can change a give as a
condition a function that prints the value of the variable and returns
0.

HTH.
Miki
Jul 18 '05 #4
> What do you need this for? If you can be more specific, we might be able
to help you a little better.


I have a Tcl/Tk script which uses a canvas to graphically represent the data
stored in the program. Whenever the data store is updated, a Tcl trace
automatically triggers to ensure the graphical display is kept consistent
with the data. I was after a simple way to convert the script to Python
Tkinter. Without the eqivalent of Tcl traces I'm probably going to have to
think about it... ;o)
Jul 18 '05 #5
In article <40**********************@freenews.iinet.net.au> ,
Derek Fountain <no****@hursley.ibm.com> wrote:
What do you need this for? If you can be more specific, we might be able
to help you a little better.


I have a Tcl/Tk script which uses a canvas to graphically represent the data
stored in the program. Whenever the data store is updated, a Tcl trace
automatically triggers to ensure the graphical display is kept consistent
with the data. I was after a simple way to convert the script to Python
Tkinter. Without the eqivalent of Tcl traces I'm probably going to have to
think about it... ;o)


Newsgroups: comp.lang.python
Subject: Re: Tcl style traces
Summary:
Expires:
References: <40**********************@freenews.iinet.net.au> <ma**************************************@python.o rg> <40**********************@freenews.iinet.net.au>
Sender:
Followup-To:
Reply-To: cl****@phaseit.net
Distribution:
Organization: The Lairds
Keywords:
Cc:

In article <40**********************@freenews.iinet.net.au> ,
Derek Fountain <no****@hursley.ibm.com> wrote:
What do you need this for? If you can be more specific, we might be able
to help you a little better.


I have a Tcl/Tk script which uses a canvas to graphically represent the data
stored in the program. Whenever the data store is updated, a Tcl trace
automatically triggers to ensure the graphical display is kept consistent
with the data. I was after a simple way to convert the script to Python
Tkinter. Without the eqivalent of Tcl traces I'm probably going to have to
think about it... ;o)


The Pythonic thing to do is to intercept the data store's set or
__setattr__ or ... method.
--

Cameron Laird <cl****@phaseit.net>
Business: http://www.Phaseit.net
Jul 18 '05 #6
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?


Would it be sufficient to keep track of attribute changes? Then you could
try something like

class TraceChanges(object):
def __init__(self, name, onChange):
# bypass the tracking mechanism
object.__setattr__(self, "name", name)
object.__setattr__(self, "changed", onChange)

def __setattr__(self, name, value):
object.__setattr__(self, name, value)
self.changed(self, name, value)
def changed(sender, name, value):
# could also be a method of TraceChanges
print "%s.%s changed to %s --> updating canvas" % (sender.name, name,
value)
rectangle = TraceChanges("rectangle", changed)
rectangle.color = "blue"

text = TraceChanges("text", changed)
text.color = "red"
text.font = "Helvetica"

Peter
Jul 18 '05 #7

"Derek Fountain" <no****@hursley.ibm.com> wrote in message
news:40**********************@freenews.iinet.net.a u...
What do you need this for? If you can be more specific, we might be able to help you a little better.
I have a Tcl/Tk script which uses a canvas to graphically represent the

data stored in the program. Whenever the data store is updated, a Tcl trace
automatically triggers to ensure the graphical display is kept consistent
with the data. I was after a simple way to convert the script to Python
Tkinter. Without the eqivalent of Tcl traces I'm probably going to have to
think about it... ;o)


There's a facility where you can associate a widget with a
variable so that when the variable changes the widget's
value changes, and vice versa. I don't offhand remember the
details though. You'll need to look at one of the references.
The variable has to be a subclass of a special Tkinter class
for this to work, though.

John Roth
Jul 18 '05 #8
In article <10*************@news.supernews.com>,
John Roth <ne********@jhrothjr.com> wrote:

"Derek Fountain" <no****@hursley.ibm.com> wrote in message
news:40**********************@freenews.iinet.net. au...
> What do you need this for? If you can be more specific, we might beable > to help you a little better.


I have a Tcl/Tk script which uses a canvas to graphically represent the

data
stored in the program. Whenever the data store is updated, a Tcl trace
automatically triggers to ensure the graphical display is kept consistent
with the data. I was after a simple way to convert the script to Python
Tkinter. Without the eqivalent of Tcl traces I'm probably going to have to
think about it... ;o)


There's a facility where you can associate a widget with a
variable so that when the variable changes the widget's
value changes, and vice versa. I don't offhand remember the
details though. You'll need to look at one of the references.
The variable has to be a subclass of a special Tkinter class
for this to work, though.

Jul 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) {...
144
by: Natt Serrasalmus | last post by:
After years of operating without any coding standards whatsoever, the company that I recently started working for has decided that it might be a good idea to have some. I'm involved in this...
13
by: Mark | last post by:
Hi This is a fairly generic question about programming style and to a certain extent garbage collection. I have some methods that I write to text logs, the event log etc at various places in...
4
by: Vinay | last post by:
Hi I want to listen to traces exhibited by other applications. Can some one help me and let me know how to do it? Can TextWriterTraceListener class be used from outside application to listen to...
0
by: Frank | last post by:
First, I borrowed the below stack trace from another posting as an example of the sort of issue I have with my own software. When I see stack traces like this from my own software, I do not...
1
by: Bob Palank | last post by:
My objective was to remove all traces of Form1 from my source which was a vcpp.Net Windows application. And I was successful - but in doing so, I lost the ability to graphically modify my form!...
2
by: michael.bierenfeld | last post by:
Hello there, how can I switch on client tracing with a c-programm connection from a aix machine to a db2 running on another aix machine. The software works fine but from time to time we loose...
6
by: rongchaua | last post by:
Hi all, I want to change the style of a button. But I don't know how to do it. For example, I have already a button OK on form. I want to add these styles to this button (WS_CHILD || WS_VISIBLE ||...
3
by: Paschat | last post by:
Hi, I installed MySQL server 5.0 on a USB key. If I plug the key in another computer runnng XP, start the server, run some queries, do some updates, stop the server and remove the key, will it...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.