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

185 questions
1
vote
1 answer

Python 2to3 conversion of imported Google libraries

I have succesfully run the Python2 Google Example Youtube upload code. Now, i want to try converting this code to Python3. When i convert it with 2to3 tool, the result is like below. And if i try to run it with Python3 i get an error such below. I…
mcan
  • 1,914
  • 3
  • 32
  • 53
1
vote
1 answer

BeautifulSoup HTMLparsingError between Python2 and Python3

I run a bs4 program on Python27, it works faultless, I am having a problem once I used Python3. I am using updated version of bs4 for both. The file I am running this on is html and I noticed the error is on a tag. Is there a supporting module I…
TChi
  • 383
  • 1
  • 6
  • 14
1
vote
3 answers

Parsing int from string with whitespace differs from py2 to py3

Parsing strings with whitespace to integers changed from Python2 to Python3. In Python2 it is: >>> int('-11') -11 >>> int('- 11') -11 whereas in Python3: >>> int('-11') -11 >>> int('- 11') Traceback (most recent call last): File "", line…
PVitt
  • 11,500
  • 5
  • 51
  • 85
1
vote
0 answers

2to3 bug: tuple index out of range, fix_raise

I have found what looks like a not tested case to me. When trying to convert following code with 2to3: def test(arg): raise() The execution stops ungracefully with no indication why, nor what file caused the problem, this is very annoying if…
dgan
  • 1,349
  • 1
  • 15
  • 28
1
vote
1 answer

Python open encoding failure

I have a script that logs data on a Windows machine (Win 7) using Python 2.7. I want to read these files on my RHEL machine using Python 3.5. I keep getting the following error (or similar): UnicodeDecodeError: 'ascii' codec can't decode byte…
tnknepp
  • 5,888
  • 6
  • 43
  • 57
1
vote
1 answer

How to port `__slots__` from Python 2 to 3

I have to port a legacy code ( ~60K LOC) from Python 2 to 3 which has a couple of thousand of structures like below: class Sample(object): __slots__ = ('both', 'advertise') class __metaclass__(type): __instancecheck__ = classmethod( …
ViFI
  • 971
  • 1
  • 11
  • 27
1
vote
1 answer

Redirect 2to3 output to new file

When I run 2to3.py -w my_script.py it converts my_script.py to Python3 and then puts the original version my_script.py.bak. I want the old file to remain as is, and the converted file to go into a new file, like my_script.converted.py. Is there a…
Superbest
  • 25,318
  • 14
  • 62
  • 134
1
vote
1 answer

Can't Parse error given when trying to use the 2to3.py to convert python code to python34

I'm having some difficulty with an error I keep getting when I try to convert some python2.7 code to python3. I know this code works in python2.7. However when I try to convert it to python3 using 2to3.py I receive this error: RefactoringTool: Can't…
Rachel
  • 11
  • 1
  • 3
1
vote
1 answer

Using 2to3 on in-memory scripts

I have a database of scripts that are in Python 2.7 format. Upon loading in my Python 3 application, I want to convert them to Python 3 format without writing each script to a file. I tried the following: from lib2to3 import refactor def…
Oliver
  • 27,510
  • 9
  • 72
  • 103
1
vote
2 answers

Traceback.py tries to compare int and 'limit' which resolves to an ImportError

I'm trying to get lettuce to run on python 3, and it's not been working. So I quickly 2to3'd all the offending files, and now I get this issue: When handling not finding terrain, lettuce crashes out due to this…
AncientSwordRage
  • 7,086
  • 19
  • 90
  • 173
1
vote
1 answer

setuptools: Run tests on build dir instead of original dir

I'm currently trying to make a module written for Python2 compatible with Python3.2. I started by making sure that all code can be automatically converted with 2to3 and added into setup.py: use_2to3 = True, So far, everything is working fine. Now,…
Nippey
  • 4,708
  • 36
  • 44
1
vote
1 answer

python 2to3 doesn't change huey file when -w argument is provided

Ok. so I know 2to3 only provides a dif list. However, 2o3 should modify the actual file right? when I run this command with -w it gives me a dif list. The file is not changed (it is still Tkinter) Also, I sse no backup like 2to3 is supposed to…
fozbstuios
  • 373
  • 4
  • 8
  • 17
1
vote
1 answer

How to enable 2to3 in python code directly?

I have a python script that needs to be started with the -3 option to check for python 3 incompatibilities. I managed to do so using the following hashtag: #!/usr/bin/python -3 But because I need to run the script in a virtualenv environment, I…
Alex
  • 41,580
  • 88
  • 260
  • 469
1
vote
1 answer

Using Z3Py With Python 3.3

My Situation I've installed Microsoft Z3 (Z3 [version 4.3.0 - 64 bit]. (C) 2006) and it's pyc binaries for Python2. I've written an Python3 package which needs access to z3 functionality. In order to be able to use the pyc binaries with my Python3…
fdj815
  • 569
  • 1
  • 7
  • 15
1
vote
1 answer

Get 2to3 to Use Spaces not Tabs

I used 2to3 to convert a folder of python modules. Everything went smooth, but when I went to run some of them it gave me an error about spaces and tabs. My theory: when 2to3 changes a line it uses tabs and not spaces unlike the rest of the…
carloabelli
  • 4,289
  • 3
  • 43
  • 70