regex (vim) for print … to print(…) for python2 to python3

后端 未结 3 1814
面向向阳花
面向向阳花 2021-01-01 20:26

This post is helpful only if you have strings inside of the print command. Now I have tons of sourcecode with a statement such as

print milk,butter
<         


        
3条回答
  •  灰色年华
    2021-01-01 21:03

    You could use 2to3 and only apply the fix for print statement -> print function.

    2to3 --fix=print [yourfiles]
    

    This should automatically handle all those strange cases which won't work with e.g. a vim regex.

    If you are missing the 2to3 shell script for some reason, run the lib as a module:

    python -m lib2to3 --fix=print [yourfiles]
    

提交回复
热议问题