Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36822
| References | <46c8a630-de27-41dc-8b8b-1951ba747447@googlegroups.com> <CAPTjJmrP4s=wba1jmfRuYiR7LeHUTiOztE_-21ibCBzzx36HgQ@mail.gmail.com> |
|---|---|
| From | Chris Kaynor <ckaynor@zindagigames.com> |
| Date | 2013-01-14 13:37 -0800 |
| Subject | Re: Finding the variables (read or write) |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.521.1358199482.2939.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
On Mon, Jan 14, 2013 at 1:28 PM, Chris Angelico <rosuav@gmail.com> 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}
>
> 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
>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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