Python 2to3 not changing files
Asked Answered
O

1

16

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.

Ogata answered 15/1, 2013 at 17:29 Comment(0)
C
17

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

2to3 -w example.py
Coppins answered 15/1, 2013 at 17:31 Comment(5)
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.Dissyllable
@Autiwa: Why are you applying individual rules? If nothing changed, then the raise rule found nothing to fix.Coppins
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.Dissyllable
@Autiwa: You won't be able to test half-translated code; you'd be much better off transforming it as a whole.Coppins
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.Dissyllable

© 2022 - 2024 — McMap. All rights reserved.