Replace all references to one object with references to other

John Gordon gordon at
Fri Aug 5 22:52:15 CEST 2011

In <mailman.1937.1312573077.1164.python-list at> Jack Bates <ms419 at> writes:

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

The simplest answer to your question is to assign object2 to object1
at the very beginning of your code, but that is a very naive solution
and can easily fail based on lots of factors.

What's your context:  A single source file?  Many source files?  A live
application with persistent data?

What are your two objects?  Do they provide an identical interface?

John Gordon                   A is for Amy, who fell down the stairs
gordon at              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

More information about the Python-list mailing list