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
0 answers

Why Python3 is slower than Python?

I have a Python program that I'm using to processed large sets of images (100k+). So even the smallest performance penalties (cited below) have a huge impact. This program originally was written in Python2, after translating it to Pythor3 it got…
1
vote
0 answers

Multiple issues with Python's code from Time Varying Graphical Lasso by David Hallac

Premise: I use Python 3.9.0 on a MacOS with Mojave (version 10.14.5). The paper "Network Inference via the Time-Varying Graphical Lasso" by David Hallac, Youngsuk Park, Stephen Boyd, Jure Leskovec comes with a Python code which can be found at…
Barbab
  • 266
  • 1
  • 8
1
vote
1 answer

Issue faced while migrating from PyQt4 to PyQt5

I have an GUI application, which is quite big.I have it in Python 2.7. Since Python 2 is no longer being updated, I converted my application to Python 3.8 using 2to3 module. I am facing this problem and have no idea how to solve it. I referred some…
Sash7
  • 73
  • 1
  • 11
1
vote
2 answers

Find all comparision between "bytes" and "str"

I am migrating one big project from Python 2 -> Python 3, the issue with comparison between "bytes" and "str" only found when the old code run into it and fail explicitly. If it falsely pass, i will not be aware. One example: def…
ThLaVi
  • 13
  • 4
1
vote
1 answer

Pyinstaller does not support Com Server and py2exe does not maintained in recent python3

We are migrating a project from python 2 to 3 that uses com server. Previously we use py2exe which works pretty well in python 2, but it is no longer maintained in the recent Python 3 release. We also tried Pyinstaller, unfortunately, it is not…
Kuku
  • 484
  • 8
  • 28
1
vote
1 answer

Migrating from Python 2.7 to 3.8: "TypeError: a bytes-like object is required, not 'str'"

In one of the files I am seeing issue: "TypeError: a bytes-like object is required, not 'str'" Code snippet: def run_process(self, cmd): sh = self.is_win() child = subprocess.Popen(cmd, stdout=subprocess.PIPE,…
codehelp
  • 21
  • 2
1
vote
1 answer

2to3 ParseError in python file

I tried running 2to3 on a python file however it is failing with following error, i am not able to understand where exactly in the problem any help is appreciated. [adsf@localhost direct]$ 2to3 ./views/statusformatter.py RefactoringTool: Skipping…
Tejas
  • 257
  • 1
  • 2
  • 13
1
vote
2 answers

How much accuracy does 2to3 Python module has to convert files?

I have whole project to convert from Python 2.x to 3.x. So can I go ahead & convert it by just 2to3 module?
1
vote
1 answer

Python 2to3 does not change #!/usr/bin/python

I am in the process of converting my python code from 2.7 to 3 using 2to3. It seems to convert as expected, except that my code always starts with the line #!/usr/bin/python which I expected to change to #!/usr/bin/python3 but it doesn't. Have I…
Mick Sulley
  • 99
  • 2
  • 11
1
vote
0 answers

black - can I rely on it flagging bad 3.x syntax?

I have some code that I have been porting from 2.7 to 3.6/3.7. Most of the unit tests, which have a pretty good coverage, already execute successfully under 3.x. But I have yet to fully commit to switching over to 3.x for development. I recently…
JL Peyret
  • 10,917
  • 2
  • 54
  • 73
1
vote
1 answer

Applying 2to3 in PyDev project in Eclipse does not affect any changes to files

I opened a Python 2 project in PyDev on Eclipse with a Python3 interpreter installed, so I get errors in certain places. The project's context menu has a PyDev -> "Apply 2to3" option. When I select it, I see diff output in my console but the .py…
user118967
  • 4,895
  • 5
  • 33
  • 54
1
vote
0 answers

Python 2 to 3: telling 2to3 "I got this"

with either linters or coverage.py, you can tell the tool to ignore certain parts of your code. for example, #pragma: no cover tells coverage not to count an exception branch as missing: except (Exception,) as e: #pragma: no cover if…
JL Peyret
  • 10,917
  • 2
  • 54
  • 73
1
vote
1 answer

Find/Test for unadorned string literals (no b" or u") in Python

As part of an effort to write code that works consistently on both Python 2 and 3, I would like to test for any unadorned string literals (any opening " or ' not preceded by a b or u). I'm fine with writing test cases, so I just need a function…
Aaron
  • 123
  • 7
1
vote
2 answers

Automatic change of defaultdict (python 3)

I encounter a problem while translating from python2 to python3 the following line: fmap = defaultdict(count(1).next) I changed count(1).next to next(count(1)) but get this error: fmap = defaultdict(next(count(1))) TypeError: first argument must…
1
vote
1 answer

Python msfrpc works with python2, throws authentication error with python 3

I'm writing a web app using python flask and python3, and would like to use the metasploit API. When writing code with python2, everything works as it should (as the lib was written for python2). However, when attempting to use it in python 3, i'm…
juddev
  • 11
  • 1