Python, doing conditional imports the right way

Put your lines into a_finder.py:

if OldVersion:
    from my.package.location.A import A
else:
    from new.package.location.A import A

Then in your product code:

from a_finder import A

and you will get the proper A.

Leave a Comment