Questions tagged [python-2to3]

2to3 is a tool for automated Python 2 to 3 code translation. Don't use this tag to ask about differences between Python 2 and Python 3. Use the [python-3.x] and [python-2.7] tags for that.

2to3 is a Python program that reads Python 2.x source code and applies a series of fixers to transform it into valid Python 3.x code. The standard library contains a rich set of fixers that will handle almost all code. 2to3 supporting library lib2to3 is, however, a flexible and generic library, so it is possible to write your own fixers for 2to3. lib2to3 could also be adapted to custom applications in which Python code needs to be edited automatically.

For more information, see the documentation at: http://docs.python.org/library/2to3.html

174 questions
4
votes
0 answers

python 2 to 3 migration error "readinto" method

I converted a huge file which I wrote it at python 2.7.3 and then now I wanted to upgrade to python 3+ (i have 3.5). what I have done so far: installed the python interpreter 3.5+ updated the environment path to read from python3+ folder upgraded…
Rebin
  • 461
  • 4
  • 15
4
votes
1 answer

Converting Python2 to Python3 with metaclasses resulted in a wrong flow

I have a very large Python 2.7.6 project which I need to convert to Python 3.4. I used 2to3 script but 'metaclass' processing seems to be broken. I filtered the code to shorten and pinpoint the problem. The following fragment works well with Python…
OGP
  • 886
  • 2
  • 11
  • 25
4
votes
2 answers

use/run python's 2to3 as or like a unittest

I have used the 2to3 utility to convert code from the command line. What I would like to do is run it basically as a unittest. Even if it tests the file rather than parts(functions, methods...) as would be normal for a unittest. It does not need to…
Vincent
  • 1,351
  • 4
  • 20
  • 37
4
votes
3 answers

Python 2to3 tool adds a vowel to my integer

I was running the 2to3 tool on various scripts I'd written to get an idea of what I will need to change to port these to Python 3 (though I will be doing it by hand in the end). While doing so, I ran into an odd change 2to3 made in one of my…
Soviero
  • 1,424
  • 1
  • 11
  • 18
4
votes
1 answer

Error Remains After Running 2to3.py on a Module

I used the 2to3.py script to convert several of my files to Python 3 a while back. I believe I need to run all fixers, so my command included -f all -f buffer -f idioms -f set_literal -f ws_comma -w I tried to run my converted code with Python 3,…
Matthew Stamy
  • 884
  • 1
  • 6
  • 9
4
votes
1 answer

Tool like 2to3, except for merges

I maintain a fork of my project for Python 3.1. When I initially made the port from 2.6, I used 2to3, but now I constantly have to merge new code from the 2.6 fork into the 3.1 fork. How can I perform the 2to3 operation on these merges…
Ram Rachum
  • 71,442
  • 73
  • 210
  • 338
3
votes
3 answers

Python 2to3 not working

I'm currently going through the python challenge, and i'm up to level 4, see here I have only been learning python for a few months, and i'm trying to learn python 3 over 2.x so far so good, except when i use this bit of code, here's the python 2.x…
bk201
  • 327
  • 2
  • 5
  • 13
3
votes
1 answer

Library to parse Python 2 and 3

I'm looking for a library that allows parsing and modification of Python 3 source code. There is the built-in ast module, but that doesn't allow parsing Python 3 code from Python 2 and vice versa. Is there such a library, or a way to make the ast…
phihag
  • 245,801
  • 63
  • 407
  • 443
3
votes
2 answers

Python 2to3 - do not remove unicode prefixes

I am converting a legacy codebase to python3 and do some dry runs of 2to3. 2to3 removes the u'' prefix from unicode literals creating a lot of noise in the diffs. Is there a way to disable this (as u'my string' is valid py3 syntax)?
Mr_and_Mrs_D
  • 27,070
  • 30
  • 156
  • 325
3
votes
2 answers

How to handle strings transparently across pythons 2 and 3 without external modules?

What would be the simplest approach to universal string handling that would work in both python2 and python3 without having to use third-party modules like six? I am ok with using if sys.version_info > (3, 0)... but can't come up with a way to…
ccpizza
  • 21,405
  • 10
  • 121
  • 123
3
votes
2 answers

Python 2to3 Script Not Working - Unicode Error

I found a repo with lots of Python2 files that includes a script to convert them to Python 3. However I get the following error when I run it: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 3-4: truncated…
Robin Andrews
  • 2,407
  • 4
  • 27
  • 62
3
votes
3 answers

RefactoringTool: ParseError: bad input: type=22, value='='

I'm refactoring some python2 code and changing it to python3 using 2to3 module. I've received following parse error: RefactoringTool: There was 1 error: RefactoringTool: Can't parse ./helpers/repo.py: ParseError: bad input: type=22, value='=',…
cmd
  • 43
  • 1
  • 4
3
votes
1 answer

Converting selenium.py to python 3 by 2to3

I'm trying to convert selenium.py written in python 2. As you see below I copied selenium.py to C:\Python32\Tools\Scripts> and after execution 2to3.py selenium.py I see that the file is the same. What Have I done wrong? Or from where I can…
user278618
  • 16,934
  • 41
  • 117
  • 192
3
votes
1 answer

Python 2to3 warning What does it mean?

I am using 2to3 to convert a script. The only warning I get is: RefactoringTool: Line 716: You should use 'operator.mul(None)' here. Line 716 of the original script is: classes = repeat(None) I don't get where shall I use operator.mul(None). The…
alec_djinn
  • 7,288
  • 8
  • 29
  • 58
3
votes
1 answer

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

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…
Dork
  • 1,630
  • 7
  • 24
  • 52
1 2
3
11 12