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


Groups > comp.lang.python > #10927 > unrolled thread

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

Started byKen Watford <kwatford@gmail.com>
First post2011-08-05 16:25 -0400
Last post2011-08-05 16:25 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#10927 — Re: Replace all references to one object with references to other

FromKen Watford <kwatford@gmail.com>
Date2011-08-05 16:25 -0400
SubjectRe: Replace all references to one object with references to other
Message-ID<mailman.1941.1312575938.1164.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web