5

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?

Błażej Michalik
  • 4,474
  • 40
  • 55
Dork
  • 1,816
  • 9
  • 29
  • 57
  • Sounds like you could use a [`FOR`](http://ss64.com/nt/for.html) loop. Or just provide the directory and the script does it automatically? – Alyssa Haroldsen Jan 21 '17 at 21:36
  • 1
    To convert all python 2 files in a directory to 3, you simply could run `$ C:\Program Files\Python\Tools\Scripts\2to3.py -w .` inside the directory that you want to translate. It would skip all the non `.py` files anyway, and remove the `-w` flag, if you don't want the backup file, – Nuhman Nov 04 '17 at 02:42

1 Answers1

9

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
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
hjpotter92
  • 78,589
  • 36
  • 144
  • 183