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

OAuth authentication, invalid signature

I tired to port the request-oauth library (based on python-request) to Python 3 (with help of 2to3) but I have problems to validate a signature with StatusNet (same API as Twitter). When I do a request to oauth/request_token, I have no problem but…
Martin Trigaux
  • 5,311
  • 9
  • 45
  • 58
0
votes
0 answers

TF Keras code adaptation from python2.7 to python3

I am working to adapt a python2.7 code that uses keras and tensorflow to implement a CNN but looks like the keras API has changed a little bit since when the original code was idealized. I keep getting an error about "Negative dimension after…
0
votes
0 answers

Running old jupyter notebooks

I am trying to use a Jupyter notebook that was written by somebody else around 8 years ago. And the contents are written in Python2 and not Python3 that I am using. I am new to it and I can't figure out the reason for the syntax error. The following…
Khushal
  • 123
  • 1
  • 4
0
votes
0 answers

after gdb read symbols from python3.11 done,gdb is stuck, not responding to whatever command is entered

### this is gdb's output. *** gdb python3.11 GNU gdb (Debian 7.12-6) 7.12.0.20161007-git Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are…
zenghuan
  • 1
  • 1
0
votes
0 answers

python 2 to 3 conversion, type instancemethod now a class method? Method no longer gets called

I am converting a large project I didn't write from python2 to python3. Most the conversion is working but some parts of our UI that applies configs does nothing. I think it is the way the method is being called and defined. An example is…
Codejoy
  • 3,722
  • 13
  • 59
  • 99
0
votes
1 answer

Settings file reference is not found

I'm working on migrating an exsting Python 2.7 project to Python 3.9. I'm facing a directory structure-related issue in Python 3. My current project directory structure is: ├───project │ ├───core | +--__init__.py | +--main.py | …
Maksim Vi.
  • 9,107
  • 12
  • 59
  • 85
0
votes
1 answer

File Inside Python Module Not Included (Django, Py2 to Py3 Conversion)

I am migrating a Django project from 2 to 3 and am running into an import(?) error. One of the apps/modules contains an __init__.py, admin.py, forms.py, models.py, urls.py, and view.py, but when the module is imported/created only admin, forms, and…
thekthuser
  • 706
  • 1
  • 12
  • 28
0
votes
0 answers

Python 2 to 3, error converting a list(zip(*aList)[1])

I have a small chunk of code which not being a python guru I am not sure what it is really 'doing', but it fails under python3: if indSoundsToPlay: indSoundsToPlay = list(indSoundsToPlay) indSoundsToPlay.sort() …
Codejoy
  • 3,722
  • 13
  • 59
  • 99
0
votes
0 answers

python2 to python3 conversion cannot find imports now. Namespacing issue?

While I am able to fix this and it is not a huge issue. I am curious if I am doing something wrong or went about something wrong. I inherited a codebase that is python2 to upgrade it to python3. So I just bit the bullet and dug in, started with a…
Codejoy
  • 3,722
  • 13
  • 59
  • 99
0
votes
0 answers

Best Practices for migrating python2 to python3 in django

It will be more helpful if you answer the following questions as well. Dealing with models.CharField. In python2, how the CharField value is stored in the database and how it is different from the value which is going to store in python3.
0
votes
0 answers

Retain Python2 dictionary iteration order in Python3

I am porting some code from python 2 to 3. data = {'direction': '->', 'src_port': 'any', 'src_ip': 'any', 'dst_port': 'any', 'dst_ip': 'any', 'action': 'alert', 'protocol': 'http'} Iterating the above dictionary in python 2 >>> for k, v in…
0
votes
1 answer

2to3.6: python conversion hanging

hi I have some python code which is generated dynamically which produces python2 code and this python generated code is executed and it's output is then used by downstream application, the problem I have is my code conversion seems to be hanging at…
vector8188
  • 1,293
  • 4
  • 22
  • 48
0
votes
0 answers

Can I use the 2to3 package or something similar from the python code itself to check if code works in Python 3 and upgrade it if not?

I want to be able to check if a function is compatible with Python 3 from the python code (not through a terminal). A string containing the function would be passed into the check. As far as I know I can only use 2to3 in the terminal to convert…
0
votes
1 answer

py2 vs py3 addition output difference in float format

a = 310.97 b = 233.33 sum= 0.0 for i in [a,b]: sum += i print(sum) py2 o/p: 544.3 py3 o/p: 544.3000000000001 Any way to report py3 output as same as py2 with futurizing? without using round-off ?
Bhanu
  • 1
0
votes
0 answers

Undo changes of '2to3' library

I had some python code in my SSH Project Folder which I had to convert from Python 2.7 to Python 3.*. Hence I installed the library 2to3. However, before running the command 2to3 . -w, I navigated to the ROOT directory which contained all the Python…
Vishnukk
  • 524
  • 2
  • 11
  • 27