[Tutor] Program Slicing / Trace

Emile van Sebille emile at fenx.com
Thu Jun 18 16:54:13 CEST 2009


On 6/18/2009 7:37 AM Jojo Mwebaze said...
> Hi Tutor
> 
> The problem i have is to see which statements modify my data at 
> execution time without referring to the code. Referring to the code is 
> difficult esp because of branching. You can never tell before hand which 
> branch execution will follow.
> 
> e.g in the example below, statements 1, 2, 5,7 and 10 modify my data and 
> are the ones i would like to trace during run time. However the other 
> statements do not change my data so am not interested in them.
> 
> How can this be achieved during execution? 

I think most of us will litter print statements through the code to 
track where something changes, then remove them once we're done. 
Sometimes I'll set a DEBUG variable or dict.  I also use pdb as needed, 
eg import pdb; pdb.set_trace()

Emile

> Not sure if the traceback 
> module can be helpful here!
> 
> Cheers
> 
> Jojo.
> 
> ===========================
> 
> def myfunction():
> 1.    num1= 20 #statement 1
> 2.    num2 = 30 #statement 2
> 3.    somelist= [ ]  #statement 3
> 4.    if (num1 < num2):
> 5.          num2 = num2 * 20 #statement 3
> 6.    else:
> 7         num2 = num1 + num2 #statement 3
> 8.    mylist = [num1, num2] #statement 4
> 9.    for items in mylist:
> 10.       somelist.append( math.sqrt(item) + math.log(item)) #statement 5
> 11.   return somelist
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list