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
-1
votes
1 answer

python testing: writing in 3 and reading in 2

I am working with a library that primarily reads and write files and needs to be interoperable in python2 and python3. I have found that sometimes a file written in python3 cannot be opened in python2 due to, for instance, string representation.…
ben.dichter
  • 1,323
  • 13
  • 10
-1
votes
3 answers

I am moving from Python 2.7 to Python 3 and .split is acting up

The prompt: Write a program that categorizes each mail message by which day of the week the commit was done. To do this look for lines that start with "from", then look for the third word and keep a runnning count of each of the days of the…
Thomas K.
  • 17
  • 2
-1
votes
3 answers

Automated Python translation 2to3 error

I want to translate Python2 code to Python 3.It is very simple,but it does not work import sys import MySQLdb import Cookbook try: conn = Cookbook.connect () print "Connected" except MySQLdb.Error, e: print "Cannot connect to server" print…
MishaVacic
  • 1,514
  • 6
  • 21
  • 26
-1
votes
1 answer

If scripts are only available on github with Python2.7, should they also release these in Python3.x alongside this? Replace the 2.7 code?

There is a substantial amount of scripts/code used for academic research written in python2.7 only available on a collaborator's github repos. The problem is this should be ported to python3.x someday. Currently, is the correct standard for users to…
ShanZhengYang
  • 12,508
  • 35
  • 106
  • 190
-1
votes
1 answer

Converting a [x][y] float back into a integer after converting Python 2.7 to 3.4

How do you convert a [x][y] float back into a integer after converting Python 2.7 to 3.4 .that is formatted as a float ex. self.table[x][y] into a integer to get the x and y values. Error I get return self.table[x][y].physics_module TypeError: list…
john taylor
  • 828
  • 10
  • 24
-1
votes
2 answers

How to use 2to3 in Python Shell?

I want to import 2to3.py in the shell, but it keeps saying SyntaxError. >>> site.addsitedir('/Python27/Tools/Scripts/') >>> sys.path ['C:\\Senti\\ltpservice', 'C:\\Python27\\Lib\\idlelib', 'C:\\Windows\\system32\\python27.zip',…
user2870222
  • 259
  • 1
  • 3
  • 12
-2
votes
1 answer

What's a good automated way to change Python 2 code to code that is compatible with Python 2 and 3?

I'm changing some Python 2 code to be compatible with Python 2 and Python 3. The translation tool 2to3 works well at converting Python 2 code to Python 3 code that is not necessarily compatible with Python 2 code. An example is how it converts…
BlandCorporation
  • 1,116
  • 10
  • 20
-2
votes
1 answer

Solve TypeError in Python/IPython

I am having trouble with the following function def get_lexographically_next_bit_sequence(self, bits): """ Bit hack from here: http://www-graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation Generator even does this in…
Unknown Coder
  • 6,201
  • 19
  • 73
  • 120
-3
votes
1 answer

python3 TypeError: a bytes-like object is required, not 'str' html

The code below works perfectly in python2.7 for thepkg in mypkgs.get('package'): pkgname = thepkg.get('name').encode('utf-8').replace(' ', '_') print(' ') but in…
Anoop P Alias
  • 303
  • 5
  • 14
1 2 3
11
12