4

I am able to load the 2to3 file in Terminal. It does a lot of printing, with output like the following:

- print str
+ print(str)  ... 

But the file is left without changes. And I don’t have any instructions after “run 2to3”. Please help.

Rory O'Kane
  • 29,210
  • 11
  • 96
  • 131
aagorobets
  • 51
  • 1
  • 2

1 Answers1

13

If you search for “2to3” the first result is the documentation for 2to3. As the documentation says, to overwrite the file instead of printing a diff, you just need to add the -w flag:

[When you run the following:]

$ 2to3 example.py

A diff against the original source file is printed. 2to3 can also write the needed modifications right back to the source file. (A backup of the original file is made unless -n is also given.) Writing the changes back is enabled with the -w flag:

$ 2to3 -w example.py
Rory O'Kane
  • 29,210
  • 11
  • 96
  • 131