473,779 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"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.p y 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_tes t.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 1803
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.p y 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.c om (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.p y 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
3735
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 I would like to work with string $sys. However, in the place where the "system()" is executed, php-file print on screen result of the
0
1353
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 tabs and spaces. We have been having flame wars about tabs vs. spaces and I was thinking this was an opinion kind of thing and it never occured to me to look at it as a simple bug that needed fixing. Give me a second of your time to pitch it that...
0
2352
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 Methods Version: $Revision: 1.34 $ Last-Modified: $Date: 2004/09/03 09:32:50 $ Author: Kevin D. Smith, Jim Jewett, Skip Montanaro, Anthony Baxter
3
11312
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: --------------------------- <xsl:for-each select="headdata/extension/person">
1
2611
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 value="2" selected="selected">Two</option> <option value="3">Three</option>
4
6490
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 count? Thanks. -Kevin -- My email address is valid, but changes periodically. To contact me please use the address from a recent posting.
2
10352
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 when run from the unix command line returns the following error:
0
4264
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 name="driver" value="COM.ibm.db2.jdbc.app.DB2Driver"/> <property name="starturl" value="jdbc:db2:temp"/> <property name="db2dir" location="${basedir}/../../../../.." /> <target name="CreateTestData" > <echo message="in mydbs db2dir = ${db2dir}" />
0
9636
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10074
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8961
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5373
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.