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


Groups > comp.lang.python > #36824

Re: Finding the variables (read or write)

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.024
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; '(without': 0.09; 'referenced': 0.09; 'def': 0.10; 'static': 0.13; 'ignore': 0.13; 'foo():': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'sorts': 0.16; 'statement.': 0.16; 'wrote:': 0.17; 'jan': 0.18; '>>>': 0.18; '(not': 0.20; "i'd": 0.22; '15,': 0.23; 'second': 0.24; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'possible,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'received:209.85.212': 0.28; 'chris': 0.28; 'cases.': 0.29; 'normally': 0.30; 'function': 0.30; 'stuff': 0.30; "aren't": 0.33; 'to:addr:python-list': 0.33; 'changed': 0.34; 'received:google.com': 0.34; 'received:209.85': 0.35; 'method': 0.36; 'anything': 0.36; 'subject: (': 0.36; 'ones': 0.37; 'quite': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'fact': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'easy': 0.60; 'first': 0.61; 'time,': 0.62; 'skip:n 10': 0.63; 'more': 0.63; '2013': 0.84; 'subject:read': 0.84; 'subject:write': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=ORCVI9qVU3NTgvyGldYfDGlrcFo9e0vSnGYTOjJqh2w=; b=q1hBFkL/8ABCagwRx1HwTVo+3mwR9+wArGuiIGC+mz2sveDDbuo7NBU6mm3/JHbV49 8h4wInGESh7nTGmdMNKiEabY3MJ95mqFtxn0svQqPwB4yM0CHqWqDfAwrhniiXB8lZY1 2urZcHJpgSNZRJgcOWJNzLG2SibpUWJ001S8Mw+U5uQMIjSfNYpejUA9SRExwcRKYU/q QRJPZGVzhlBnSi8OQ87U0hPVYHbCUlEmmjiwhjvvOuxgctHXy+JoSbWPOGyvpToBbN8K 8l7LrU8iJMZl7CzFfwSlb622Oe7MdCmh/lhJmZIigpBgyNxJHWOq7W7611NTp5xSpuaz e/rA==
MIME-Version 1.0
In-Reply-To <CALvWhxvMo1_9CrSgQh-1q1V7wZkt-gVKFxCqVkCzoU_P0+M38A@mail.gmail.com>
References <46c8a630-de27-41dc-8b8b-1951ba747447@googlegroups.com> <CAPTjJmrP4s=wba1jmfRuYiR7LeHUTiOztE_-21ibCBzzx36HgQ@mail.gmail.com> <CALvWhxvMo1_9CrSgQh-1q1V7wZkt-gVKFxCqVkCzoU_P0+M38A@mail.gmail.com>
Date Tue, 15 Jan 2013 08:46:39 +1100
Subject Re: Finding the variables (read or write)
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
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.523.1358200002.2939.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1358200002 news.xs4all.nl 6935 [2001:888:2000:d::a6]:60813
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:36824

Show key headers only | View raw


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