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


Groups > comp.lang.python > #10927

Re: Replace all references to one object with references to other

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <kwatford@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'cpython': 0.05; 'instance,': 0.05; 'pointer': 0.05; 'option,': 0.07; 'pypy': 0.07; 'subject:object': 0.07; 'python': 0.08; 'iterate': 0.09; 'structure.': 0.09; 'cpython,': 0.16; 'dangerous,': 0.16; 'labeled': 0.16; 'narrow': 0.16; 'pointer,': 0.16; 'try?': 0.16; 'cc:addr:python-list': 0.16; 'this:': 0.16; 'wrote:': 0.16; 'level,': 0.18; 'cc:no real name:2**0': 0.20; 'memory': 0.21; 'cc:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'objects,': 0.23; 'pm,': 0.24; 'aug': 0.24; 'object,': 0.24; 'url:doc': 0.25; 'function': 0.27; 'done.': 0.28; 'message-id:@mail.gmail.com': 0.29; 'second': 0.29; 'cc:addr:python.org': 0.30; 'easier.': 0.30; 'object.': 0.30; 'changing': 0.31; 'values': 0.32; 'references': 0.32; "isn't": 0.33; 'it.': 0.33; "can't": 0.33; 'instead': 0.33; 'reference': 0.35; 'object': 0.35; 'received:209.85.161': 0.35; 'fri,': 0.36; 'using': 0.37; 'but': 0.37; 'two': 0.37; 'could': 0.38; 'some': 0.38; 'received:google.com': 0.38; 'url:org': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'url:en': 0.39; 'subject:with': 0.39; 'equal': 0.39; 'data': 0.39; 'might': 0.40; 'your': 0.61; 'address': 0.61; 'subject:one': 0.77; 'difficult.': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=E/+TZPXHJ8u5DZOf+zj4B/bVOFuDJF3EAzFqUemGZWM=; b=vGIjceymMIoSj1Xov36ES2DiomPcqGas/J0UHoEArnPUPU2WfA6AP2JXZhCreSlS9X z81VGUg6YOedbymUyEAMeptq55oAIm3sz8wcMZOyKy1/p2cfr7gU+0upAxvK+QH32Py0 AtO8cjOyXiCQiqcn6xJk0Z7lCqUccxSOD6zyA=
MIME-Version 1.0
In-Reply-To <1312573041.6831.7.camel@selene>
References <1312573041.6831.7.camel@selene>
From Ken Watford <kwatford@gmail.com>
Date Fri, 5 Aug 2011 16:25:17 -0400
Subject Re: Replace all references to one object with references to other
To Jack Bates <ms419@freezone.co.uk>
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
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.1941.1312575938.1164.python-list@python.org> (permalink)
Lines 19
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1312575938 news.xs4all.nl 23865 [2001:888:2000:d::a6]:41003
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:10927

Show key headers only | View raw


On Fri, Aug 5, 2011 at 3:37 PM, Jack Bates <ms419@freezone.co.uk> wrote:
> I have two objects, and I want to replace all references to the first
> object - everywhere - with references to the second object. What can I
> try?

If using PyPy instead of CPython is an option, the "thunk" object
space's "become" function can apparently do this:
http://doc.pypy.org/en/latest/objspace-proxies.html#the-thunk-object-space

In CPython, this might be a tad difficult. At the C level, a reference
to a python object is just a pointer to it. You could iterate through
the entire address space looking for values that equal a particular
pointer, but changing them would be dangerous, since memory isn't
labeled by type - you can't tell if the memory is a pointer to your
object or an important part of some other data structure.

If you could narrow down what you want to accomplish, this might be
easier. For instance, if all you need is to replace module-level
references to the object, that can be done.

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


Thread

Re: Replace all references to one object with references to other Ken Watford <kwatford@gmail.com> - 2011-08-05 16:25 -0400

csiph-web