How to use 2to3 to translate all files in a directory

Dork picture Dork · Jan 21, 2017 · Viewed 8.1k times · Source

I'm able to translate one file. But I don't understand how to translate whole directory. From docs:

To translate an entire project from one directory tree to another use:
$ 2to3 --output-dir=python3-version/mycode -W -n python2-version/mycode

Can you give me a concrete example? I have python2 files in D:\Dir1 and want to get new files in D:\Dir2. I'm now in the command prompt inside Dir1 typing c:\Users\........\Python36\Tools\scripts\2to3.py -w

So what is the command that should I use?

Answer

hjpotter92 picture hjpotter92 · Jan 21, 2017

Try the following:

D:\Dir1> c:\Users........\Python36\Tools\scripts\2to3.py --output-dir=D:\Dir2 -W -n .\

Notice that it is a -W (capital W).


As an example, I ran the script from my home directory:

┌─[hjpotter92:Hedwig]─[C:\Users\hjpotter92]
└──$ "C:\Program Files\Python\Tools\Scripts\2to3.py" -o Downloads\newFoo -W -n Downloads\Foo