interface like behavior for mudules

paolo_veronelli paolo_veronelli at yahoo.it
Fri Feb 18 11:28:40 EST 2005


Hello  pyple,

I have two modules :remote.py  and local.py which have some classes with 
the same names specifically one we can call Model.So it exist 
remote.Model class and local.Model class

A third module called uri.py  derives some of its classes from a not 
better specified repository.Model

at the beginning of uri.py I can write 'import local as repository' or 
'import remote as repository'. In either cases the module uri is ready 
to be imported from a fourth module

Now I have two applications ,say applocal.py and appremote.py. Both 
import uri as a module ,but the first wants uri to have imported local 
as repository and the second wants uri to have imported remote as 
repository.

In pseudo language applocal.py would have 'import uri with local as 
repository'  at the beginning and appremote.py would have 'import uri 
with remote as repository'

I wonder if there is a way to keep uri unique,because as it is now I 
have to keep two modules,say urilocal and uriremote which differs only 
for a line at the top.

I suppose __import__ is there to help me, but I have no idea on how.

Hope I have been clear,thanks for considerations and help

Yours Paolino




More information about the Python-list mailing list