Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36824
| References | <46c8a630-de27-41dc-8b8b-1951ba747447@googlegroups.com> <CAPTjJmrP4s=wba1jmfRuYiR7LeHUTiOztE_-21ibCBzzx36HgQ@mail.gmail.com> <CALvWhxvMo1_9CrSgQh-1q1V7wZkt-gVKFxCqVkCzoU_P0+M38A@mail.gmail.com> |
|---|---|
| Date | 2013-01-15 08:46 +1100 |
| Subject | Re: Finding the variables (read or write) |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.523.1358200002.2939.python-list@python.org> (permalink) |
On Tue, Jan 15, 2013 at 8:37 AM, Chris Kaynor <ckaynor@zindagigames.com> wrote:
> And those aren't even covering the case that a, normally non-mutating,
> method actually mutates.
If it's static analysis, I'd quietly ignore those sorts of cases.
Anything can be changed any time, including stuff that's completely
unrelated to what you're working on.
Now, if the OP just wants to know what names get referenced (without
distinguishing reads from writes), that's quite possible, and in fact
easy - if you're willing to analyze a whole function instead of a
single statement.
>>> def foo():
x=y+1
>>> foo.__code__.co_varnames
('x',)
>>> foo.__code__.co_names
('y',)
The first one is the ones that get assigned to (not quite the same as
"written to"), the second is ones that don't. Well, more or less. In
simple cases.
ChrisA
Back to comp.lang.python | Previous | Next — Previous 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