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

Steganography program - converting python 2 to 3, syntax error in: base64.b64decode("".join(chars))

I have problem with the syntax in the last part of steg program. I tried to convert python 2 version (of the working code) to python 3, and this is the last part of it: flag = base64.b64decode("".join(chars)) <- error print(flag) The program 1.…
0
votes
2 answers

Hashing salted string multiple times (custom password hashing)

I need to port old Python 2 code to Python 3 and I think I'm messing up with string encoding. It's a custom password hasher. I've tried different ways, unsuccessfully, obtaining only errors or wrong results. This is the Python 2 code which needs to…
pedrotech
  • 1,359
  • 10
  • 19
0
votes
4 answers

updating from python 2 to python 3

I'm updating a script written in python 2 to python 3 which I'm learning while trying to use. this wxpython controlled LED class is causing an error: (TypeError: Expected a list of bytes objects.) I believe the problem stems from this list xpm =…
0
votes
0 answers

Ansible: dynamic inventory module not found error

I am trying to configure dynamic inventory in my ansible code with AWS Here is the configuration in ansible.cfg [defaults] inventory = ./inventory/ec2.py When I try to check to verify the host with ansible -m command -a "ls" all i am getting…
shamon shamsudeen
  • 5,466
  • 17
  • 64
  • 129
0
votes
0 answers

Error in executing python scripts as modules with python -m option in python3

I am migrating my code from python2 to python3 and I am facing following issue with python3 -m command. I have a python script which in some cases may be compiled(.pyc) or non-compiled(.py) so I am not sure whether it is .py or .pyc but I wanted to…
0
votes
0 answers

Basestring equivalent in Python3 / str and string_types from future and six not working

I have a script written in python 2.x that checks the data type for a number of different unseen variables. I try to move the code to python 3.x and one of the variables is crushing my program its value is date:2018-04-21 04:00:10. I catch the error…
Zisis F
  • 322
  • 5
  • 11
0
votes
1 answer

Issues with module imports going from python 2 to python 3

I am trying to upgrade a 10 year old event listener that I didn't write from Python 2.7 to python 3.7. The basic issue I'm running into is the way the original script was importing its plugins. The idea behind the original script was that any…
Adam Benson
  • 11
  • 1
  • 4
0
votes
1 answer

Are there differences between string.replace / .strip / .find and the built-in functions?

I have a Python 2 codebase which I'm migrating to Python 3. The old codebase uses import string foo = string.replace(s, old, new) foo = string.strip(s) foo = string.find(s, sub, start, end) I moved it with 2to3, but this gives an error. My guess…
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
0
votes
2 answers

TypeError: can't concat str to bytes when converting Python 2 to 3 with Encryption Function

I am trying to transfer a code from python2 to 3. The problem happens. "pad * chr(pad)" looks like a string but when I print it out it shows . I dont know what it is really is. in aesEncrypt(text, secKey) 43 def…
Roy Dai
  • 483
  • 2
  • 5
  • 15
0
votes
1 answer

Turning 'bytes' into 'str': Why is a '\' added to '\n' and such?

I read various lines from a CSV file like this: f1 = open(current_csv, 'rb') table = f1.readlines() f1.close() So essentially any single line in table is something like this: line = b' G\xe4rmanword: 123,45\r\n' which type tells me is…
JC_CL
  • 2,346
  • 6
  • 23
  • 36
0
votes
1 answer

Why does future.types.newstr.newstr.str.__mod__ return Unicode?

I'm working on the support of Python 2 and 3 at the same time and I have some weird things that I wasn't able to understand so far. I'm using the python-future module in order to achieve this transition. When I use the __mod__ function on an newstr…
bastantoine
  • 582
  • 4
  • 21
0
votes
2 answers

Converting Django project from Python 2 to Python 3: django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet

I am converting a Django website from Python 2 to Python 3. To do this, I ran 2to3 on the whole project. Now, upon running the server (which works fine in Python 2). Now, there appears to be an error django.core.exceptions.AppRegistryNotReady: Apps…
woefipuasd
  • 23
  • 4
0
votes
1 answer

Converting Django project from Python 2 to Python 3: pip3 install django_comments NameError unicode

System info: 64-bit OS-X, Python 3.7 I am converting a Django website from Python 2 to Python 3. To do this, I ran 2to3 on the whole project. I then installed all of the required modules in INSTALL_APPS in settings.py - except one:…
woefipuasd
  • 23
  • 4
0
votes
1 answer

Unable to decode bytearray in python 3 but possible in python 2

I am trying to print a bytearray as a string of ascii characters in Python 3. I have a bytearray which I have tried to print using both Python 2 and Python 3. In Python 2 the bytearray is printed to the console in proper ascii characters. However,…
0
votes
1 answer

LookupError: 'base64' is not a text encoding when upgrading code from Python2 to Python3

I have a piece of Python2 code that i would like to upgrade to Python3. It is a Cinder storage driver that communicates with and API. Most of the code i could 'convert' myself or with the help of 2to3. I'm no programmer, but am willing to learn. I…
PetervdS
  • 7
  • 1
  • 4