473,246 Members | 1,492 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,246 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 1777
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: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.