In a python project , how can achieve fully backward compatibility ?

Monday, July 7, 2014

I have directory structure like :



foo/
--foofile.py
--__init__.py

--first/
--first/__init__.py
--first/module1_in_first.py
--first/module2_in_first.py

--second/
--second/__init__.py
--second/somefile_in_second.py


Now I have renamed folder foo and named it bar. For backward compatibility, in the init file of new folder (bar), I've imporded sys and written sys.modules['foo'] = sys.modules['bar'] and that works well. When I write 'import module1_in_first' in module2_in_first.py and print it, it gives me '< module 'foo.first.module1_in_first' from '/home/myproject/bar/first/module1_in_first.pyc'>'. Now what if I want to have this module as < module 'bar.first.module1_in_first' > ?







http://ift.tt/1smA6TZ