473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

"Visually following", line by line, the execution of a program

I want to "import and execute" a python program (input_test.py below)
within another program (execute_test.py below) and "watch it" being
executed.
By watching it, I mean to display the file input_test.py in a window
(GUI) and
highlighting the line being executed.
I am *simulating* this here by printing the line being executed with
the corresponding line number and it works as expected for "simple"
programs.

The problem arises when I want to do a loop (or other similar blocks).
If I write a loop as

for i in range(2):
print i

exec() gives an EOF error, as it processes the "for" line.
I have tried to put the loop on a single physical line, something like
for i in range(2):\n print i

but this didn't work either. I really would like to be able to
follow within the loops too...
Any pointer would be greatly appreciated.

Andre Roberge

Btw, input_test.py is already processed to tag on the ";NUM = ...".
It is not the file as I would want it to appear on a window being
traced.

===== File Constants.py ====
NUM = 1

===== File input_test.py ===
from Constants import * ; NUM = 2
print "Starting within input_test"; NUM = 3
print "Within input_test, NUM =", NUM; NUM = 4
print "Done!"

===== File execute_test.py ===
import time
from Constants import *
inp = open("input_test.py", "r")

for line in inp.readlines():
print "NUM =", NUM, ":",
exec(line)
time.sleep(1)

inp.close()

======= Output from the program =====
NUM = 1 : NUM = 2 : Starting within input_test
NUM = 3 : Within input_test, NUM = 3
NUM = 4 : Done!
Jul 18 '05 #1
2 1783
Andr? Roberge <an***********@ns.sympatico.ca> wrote:
I want to "import and execute" a python program (input_test.py below)
within another program (execute_test.py below) and "watch it" being
executed.
By watching it, I mean to display the file input_test.py in a window
(GUI) and highlighting the line being executed.


The functionality you require is known as 'tracing'.

See section 9.2, "How it works", in the Python Library Reference, for
all details. With sys.settrace, you establish your chosen 'tracing
function', and it gets called with three arguments, frame, event, arg.
event is a string which can be 'call', 'line','return', 'exception'.
The 'line' event is the main one you care about: from the frame object
you can find out what file and line is about to be executed. Be sure to
have the trace function return itself if it wants to keep tracing,
because for most events the trace function's return value is taken as
the new trace function to use (locally, i.e. within the function
currently being traced) for future tracing, None meaning stop tracing
(at this level of function call).
Alex
Jul 18 '05 #2
al*****@yahoo.com (Alex Martelli) writes:
Andr? Roberge <an***********@ns.sympatico.ca> wrote:
I want to "import and execute" a python program (input_test.py below)
within another program (execute_test.py below) and "watch it" being
executed.
By watching it, I mean to display the file input_test.py in a window
(GUI) and highlighting the line being executed.


The functionality you require is known as 'tracing'.

See section 9.2, "How it works", in the Python Library Reference, for
...


You can find an implementation in our graph algorithm visualization
software Gato (http://gato.sf.net). It should be trivial to strip out
the necessary code.

Best,
Alexander
--
Alexander Schliep sc*****@molgen.mpg.de

Jul 18 '05 #3

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

Similar topics

2
by: opt_inf_env | last post by:
Hallo, I want to see from php-file list of files which are in directory, where is the given php-file. To do so, I put in the php-file the following line: <?php $sys = system("ls") ?> Then...
0
by: Mark Hahn | last post by:
Ville Vainio came up an idea for one final tweak of the tab/space indent algorithm we are using in Prothon, and the final result surprised me, in that it directly addresses the problem of mixed...
0
by: Anthony Baxter | last post by:
To go along with the 2.4a3 release, here's an updated version of the decorator PEP. It describes the state of decorators as they are in 2.4a3. PEP: 318 Title: Decorators for Functions and...
3
by: Peter Rohleder | last post by:
Hi, I'm using a style-sheet where I make use of the XPATH-"following-sibling"-expression. The part which makes problems looks similar to the following code: --------------------------- ...
1
by: Niall Smart | last post by:
Hi I'm trying to emulate a "following-sibling-or-self" XPath axis without using the union operator. The XML looks like this: <deeply-nested> <select> <option value="1">One</option> <option...
4
by: Kevin Goodsell | last post by:
The return value of sscanf should be "the number of input items assigned" (unless an input failure occurs before any conversion). Are items assigned due to a "%n" directive included in the returned...
2
by: Marty Meyers | last post by:
I have the following line in a php file: $msg= exec("perl $scriptPath/insert.pl $d $u $t 2>&1", $returnVal); Can someone explain the "2>&1" argument? Second problem, this same line of code...
0
by: vaibhavsumant | last post by:
<project name="DBCreate" default="usage" basedir="."> <property name="user" value="db2admin"/> <property name="passwd" value="db2admin"/> <property name="dbprefix" value=""/> <property...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.