Import Replacement

James Pruitt eric.pruitt at gmail.com
Sat Jan 31 14:23:37 EST 2009


Imagine there are two files horse.py and buffalo.py. horse.py is imported by
another file rider.py. Is it possible to make it so that under certain
circumstances possibly based on an environment variable or something similar
that when rider.py imports horse.py, it actually imports buffalo.py sort of
like a behind the scenes replacement so that rider.py needs little,
preferably absolutely no modification? Right now, I am investigating the use
of sys.modules and doing something using sys.modules['horse.py'] =
'buffalo.py'.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090131/31c5cad2/attachment.html>


More information about the Python-list mailing list