0

As I read the question. I came up with an idea. But I don't know the consequences of my guesswork.

My idea is that change the import strategy by modify the sys.modules, then change the import things without modify old code.

Edit 1

A situation use the method

Hack code:

try:
    import concurrent.futures
except ImportError:
    concurrent.futures = wrapper_futures

Then this code can use for python2 and python3

Old code:

from concurrent.futures import Future
Community
  • 1
  • 1
Goat
  • 188
  • 7

1 Answers1

1
 try:
     from servicelibrary.simple import synchronous
 except ImportError:
     from servicelibrary.simple import alternative as synchronous

is probably a better way to do it if I understand your question properly

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
  • If my old code is in other files and I don't want to modify so many old code. Do you have a better way? – Goat Nov 01 '13 at 15:52
  • 1
    the biggest problem with your code is that its not very clear from reading it what it is doing ... just think if you need to go back and modify it in a year will you understand it? will someone else working on the project be able to understand what you are doing? – Joran Beasley Nov 01 '13 at 15:53