tags:

views:

42

answers:

2

Is there a way to change python2.x source code to python 3.x manually. I guess using lib2to3 this can be done but I don't know exactly how to do this ?

+1  A: 

Yes, porting is what you are looking here.

Porting is a non-trivial task that requires making various decisions about your code. For instance, whether or not you want to maintaing backward compatibility. There is no single, universal solution to porting. The way you port depends on your specific requirements.

The best resource I have found for porting apps from Python 2 to 3 is the wiki page PortingPythonToPy3k. The page contains several approaches to porting as well as a lot of links to resources that are potentially helpful in porting work.

jsalonen
A: 

Thanks. Here is the answer I was looking for:

from lib2to3.refactor import RefactoringTool, get_fixers_from_package

//assume files to a be a list of all filenames you want to convert

r = RefactoringTool(get_fixers_from_package('lib2to3.fixes'))

r.refactor(files, write=True)

pkumar