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


Groups > comp.lang.python > #36823

Re: Finding the variables (read or write)

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'syntax': 0.03; 'debugging': 0.05; 'python': 0.09; '###': 0.09; 'ast': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terry': 0.09; 'resulting': 0.13; '(read': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'written.': 0.16; 'wrote:': 0.17; 'have:': 0.17; 'instance': 0.17; 'instance,': 0.17; 'variables': 0.17; '(in': 0.18; 'jan': 0.18; 'module': 0.19; 'question.': 0.20; 'written': 0.20; "i'd": 0.22; 'example': 0.23; '15,': 0.23; 'statement': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '(which': 0.26; 'am,': 0.27; '(3)': 0.27; 'c++': 0.27; 'to?': 0.27; 'header:X-Complaints-To:1': 0.28; 'lines': 0.28; 'chris': 0.28; 'python).': 0.29; 'case,': 0.29; 'definition': 0.29; 'read,': 0.29; 'source': 0.29; 'function': 0.30; 'code': 0.31; '(2)': 0.32; 'to:addr:python-list': 0.33; 'another': 0.33; '(1)': 0.34; 'pm,': 0.35; 'received:org': 0.36; 'tool': 0.36; 'subject: (': 0.36; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'matter': 0.61; 'state.': 0.71; '2013': 0.84; 'etc,': 0.84; 'received:fios.verizon.net': 0.84; 'subject:read': 0.84; 'subject:write': 0.84; 'fibonacci': 0.91; 'write:': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Finding the variables (read or write)
Date Mon, 14 Jan 2013 16:42:42 -0500
References <46c8a630-de27-41dc-8b8b-1951ba747447@googlegroups.com> <CAPTjJmrP4s=wba1jmfRuYiR7LeHUTiOztE_-21ibCBzzx36HgQ@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/17.0 Thunderbird/17.0
In-Reply-To <CAPTjJmrP4s=wba1jmfRuYiR7LeHUTiOztE_-21ibCBzzx36HgQ@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.522.1358199785.2939.python-list@python.org> (permalink)
Lines 37
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1358199785 news.xs4all.nl 6923 [2001:888:2000:d::a6]:58484
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:36823

Show key headers only | 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