Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #36823

Re: Finding the variables (read or write)

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Finding the variables (read or write)
Date 2013-01-14 16:42 -0500
References <46c8a630-de27-41dc-8b8b-1951ba747447@googlegroups.com> <CAPTjJmrP4s=wba1jmfRuYiR7LeHUTiOztE_-21ibCBzzx36HgQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.522.1358199785.2939.python-list@python.org> (permalink)

Show all headers | View raw


On 1/14/2013 4:28 PM, Chris Angelico wrote:
> On Tue, Jan 15, 2013 at 6:48 AM,  <servekarimi@gmail.com> 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}

I would try compiling the source code to an ast (abstract syntax tree). 
See the ast module for how to do that and how to 'read' the resulting tree.

> 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?

'self' is read, 'lst' is written to.

  What about:
>
> self.lst.append(self.lst[-1]+self.lst[-2])
>
> (which might collect Fibonacci numbers)?

'self' read, 'lst' read and written. Knowing that for non-builtins is 
another matter ;-).

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Finding the variables (read or write) servekarimi@gmail.com - 2013-01-14 11:48 -0800
  Re: Finding the variables (read or write) Chris Angelico <rosuav@gmail.com> - 2013-01-15 08:28 +1100
  Re: Finding the variables (read or write) Chris Kaynor <ckaynor@zindagigames.com> - 2013-01-14 13:37 -0800
  Re: Finding the variables (read or write) Terry Reedy <tjreedy@udel.edu> - 2013-01-14 16:42 -0500
  Re: Finding the variables (read or write) Chris Angelico <rosuav@gmail.com> - 2013-01-15 08:46 +1100

csiph-web