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

Make Python 2 compatible with Python 3

My current requirement is to write a script in Python 2.4.3 which comes bundled wit RHEL 5 . But few years down the line say 5 yrs ,the server may be upgraded to RHEL 8 or 9 which comes with Python 3. So I am supposed to write the code which is…
v1shnu
  • 2,211
  • 8
  • 39
  • 68
0
votes
1 answer

Problem with literal arguments in the PATTERN string for a python 2to3 fixer

I'm writing a fixer for the 2to3 tool in python. In my pattern string, I have a section where I'd like to match an empty string as an argument, or an empty unicode string. The relevant chunk of my pattern looks like: (args='""' | args='u""') My…
Zxaos
  • 7,791
  • 12
  • 47
  • 61
0
votes
1 answer

2to3 not working

I'm converting a single module using 2to3. test_lib2to3.py is in /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/test/test_lib2to3.py File to be converted is in /Users/Nimbuz/Documents/python31/Excercise 1/time3.py Terminal…
eozzy
  • 66,048
  • 104
  • 272
  • 428
0
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
  • 269
  • 1
  • 3
  • 13
0
votes
1 answer

Python install of setup.py files not running 2to3

Recently, when trying to install the pyglet module for openGL in python, I have run into a problem. It appears that when running a setup.py file, it is not converted with 2to3. Due to this issue, I am unable to use pyglet in python 3 due to errors…
NAME__
  • 625
  • 1
  • 7
  • 17
0
votes
1 answer

Translating Python 2 code to Python 3

Can anybody help me translating this python 2 code to python 3 without using the 2to3 tool ? import urllib2, cookielib self.cj = cookielib.MozillaCookieJar(self.cookie_file) self.opener = urllib2.build_opener( …
sgp
  • 1,738
  • 6
  • 17
  • 31
0
votes
1 answer

How to call 2to3 before run py2app

I have a setup.py that use py2app, and I want to run 2to3 to convert python script to Python 3 compatible before build the app. I used option setup(use_2to3=True), but it did not call 2to3. So now I use a Makefile to work around this problem. Any…
user326503
0
votes
1 answer

IRCUtils: Cannot make memory view because object does not have the buffer interface

I'm playing about with the idea of making a simple IRC bot. It seems like there is a variety of Python software written for this purpose, with varying feature sets and varying degrees of complexity. I found this package which seems to have a pretty…
Hammerite
  • 21,755
  • 6
  • 70
  • 91
0
votes
1 answer

Where to find build_tests command?

When I was reading examples for testing a package in multiple pythons with tox I found about a command "build_tests" that would put (2to3'd) test files in build/ directory. I could also google it in some projects' tox.ini files and some gentoo…
zefciu
  • 1,967
  • 2
  • 17
  • 39
-1
votes
1 answer

Python 2.7 to 3.7 tkinter scrolledtext is not behaving

I have a Python 2.7 GUI using Tkinter and porting it to 3.7 It pipes a subprocess stdout to a scrolledtext widget and works fine with 2.7 but with 3.7 it is constantly updating the widget and I cannot scroll. Code snippet: #lauch main proc =…
MarkB
  • 7
  • 2
-1
votes
2 answers

TypeError: '<' not supported between instances of pyshipping.Package after running 2to3

Python newbie here, very good chance I am doing a silly mistake here.. After losing a good amount of hair and searching for many hours, I am still not able to convert a whole project to python 3. I have a project made in django framework and it uses…
Rohit Kumar
  • 684
  • 2
  • 17
  • 39
-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,663
  • 15
  • 11
-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,812
  • 8
  • 25
  • 29
-1
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,625
  • 20
  • 79
  • 129
1 2 3
12
13