pythonpython-2.7sedbackport

Automatically backport python 2.7 to 2.6


I need to run some Python 2.7 code under Python 2.6 and I was wondering how that could be automated.

Some specific simple changes are

sed -i -e 's/:,d/:d/g' -e 's/{0}/set([0])/g' foo.py

However, I also need to replace

with open(foo) as f, open(bar) as b:
    ...

with

with open(foo) as f:
 with open(bar) as b:
    ...

and it is much less obvious for me (I need to get the indentation right and my sed-foo is not enough here).

Any suggestions?


Solution

  • No, don't use sed. What you need is an IDE that understands refactoring or macros. For example, here's what I would do in vim:

    Then you iterate through the searches and press @a to replay the macro.