13

I have a bunch of modules written in python 2.x and I need them to be in 3.x for them to work. I ran 2to3 on the entire folder, and it seemed to work fine, but when I looked at the files again they were the same. I have not used 2to3 and was wondering if it saves the converted files in some other directory.

nbro
  • 12,226
  • 19
  • 85
  • 163
carloabelli
  • 4,041
  • 3
  • 35
  • 64

1 Answers1

17

You need to tell 2to3 explicitly to actually write the changes, using the -w switch:

2to3 -w example.py
Martijn Pieters
  • 889,049
  • 245
  • 3,507
  • 2,997
  • I use the following command: > 2to3 -n -w -f raise . And 2to3 explicitely tells: > RefactoringTool: Files that need to be modified: > : ./ez_setup.py > RefactoringTool: ./setup.py And doesn't change anything. I don't have a clue why. I have the write and no-backup option. It worked for the "print" rule. – Autiwa May 07 '18 at 14:36
  • @Autiwa: Why are you applying individual rules? If nothing changed, then the `raise` rule found nothing to fix. – Martijn Pieters May 08 '18 at 19:15
  • I apply individual rules because there's a lot of them and I want to test the code inbetween, or I won't be able to reverse one rule without reverting everything in my version control system. Plus, the raise rule find something, because it says "files that need to be modified", but doesn't actually do something. – Autiwa May 09 '18 at 20:33
  • @Autiwa: You won't be able to test half-translated code; you'd be much better off transforming it as a whole. – Martijn Pieters May 09 '18 at 21:07
  • I can't test it because other module are not translated yet. That's why I want to separate things, because much of the code can't be tested, some import fail. Thanks you for trying to help me, maybe it's better your way, but I really want to use 2to3 that way and that's what I'd like to understand. Then I can understand what 2to3 does for separate rules. – Autiwa May 11 '18 at 04:51