On Mon, Jan 14, 2013 at 1:28 PM, Chris Angelico <(E-Mail Removed)> wrote:

> On Tue, Jan 15, 2013 at 6:48 AM, <(E-Mail Removed)> wrote:

> > I'd like to develop a small debugging tool for python programs.In

> Dynamic Slicing How can I find the variables that are accessed in a

> statement? And find the type of access (read or write) for those variables

> (in Python).

> > ### Write: A statement can change the program state.

> > ### Read : A statement can read the program state .

> > **For example in these 4 lines we have:

> > (1) x = a+b => write{x} & read{a,b}

> > (2) y=6 => write{y} & read{}

> > (3) while(n>1) => write{} & read{n}

> > (4) n=n-1 => write{n} & read{n}

>

> An interesting question. What's your definition of "variable"? For

> instance, what is written and what is read by this statement:

>

> self.lst[2] += 4

>

> Is "self.lst" considered a variable? (In C++ etc, this would be a

> member function manipulating an instance variable.) Or is "self" the

> variable? And in either case, was it written to? What about:

>

> self.lst.append(self.lst[-1]+self.lst[-2])

>

> (which might collect Fibonacci numbers)?

>
And those aren't even covering the case that a, normally non-mutating,

method actually mutates. Consider the following class (untested):

class Test(object):

def __init__(self, value):

self.value = value

self.adds = 0

def __add__(self, other):

self.adds += 1

other.adds += 1

return Test(self.value + other.value)

With that class,

x = a + b

would mutate x, a, and b, presuming a and b are instances of Test.

>

> ChrisA

> --

> http://mail.python.org/mailman/listinfo/python-list

>