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

import issue when transferred from py2 to py3

I have following directory structure: content\ip_low_level\unit_tests\dd\dd.py each directory has __init__.py when I'm trying to run dd.py, it is giving following error: Traceback (most recent call last): File…
Dibyendu Dey
  • 349
  • 2
  • 16
0
votes
1 answer

How can I use/authenticate msfrpc with python3.x?

Edited: The code below works, and the changes are commented. As noted, with python3 one must prefix the string literals with a "b" to produce an instance of the byte type instead of a Unicode str type. I'm trying to use msfrpc (written in Python…
vdud3
  • 1
  • 3
0
votes
0 answers

py2 and py3 compatible code to replace extended unpacking (*args) in function

I have some python3 code that I'm trying to make compatible with python2. This has mostly been easy using the six package and __future__, but I can't find a way around 'extended unpacking' (i.e. using the *args syntax). For example, the…
DilithiumMatrix
  • 17,795
  • 22
  • 77
  • 119
0
votes
1 answer

where is the module level string.upper function in Python 3?

How do I get this code to work in 3? Please note that I am not asking about "foo".upper() at the string instance level. import string try: print("string module, upper function:") print(string.upper) foo = string.upper("Foo") …
JL Peyret
  • 10,917
  • 2
  • 54
  • 73
0
votes
0 answers

Python 2 to 3 conversion: 'TypeError: missing required positional argument:'

I'm new to Python (and to stackoverflow) and my first task is to convert an energy flow simulation program from Python 2.7 to Python 3.6 and get it running on 3.6. I already used the 2to3 converter and solved some other errors but now I'm hitting a…
Hen Ren
  • 29
  • 6
0
votes
1 answer

Error when importing BeautifulSoup in Python

Executing script with usage of from bs4 import BeautifulSoup gives the following error: Traceback (most recent call last): File "C:\Users\Stewart\Desktop\dorkscan.py", line 13, in from bs4 import BeautifulSoup File…
0
votes
1 answer

In memory gzip/gunzip of string - how to migrate python2.7 to python3

I use the following utility in Python2.7 to gzip/gunzip string/stream in memory. I need help figuring out how to deal with BytesIO vs StringIO in python3 to migrate following: from StringIO import StringIO import…
sky
  • 2,531
  • 4
  • 17
  • 15
0
votes
0 answers

Having troubles with urlib when using "2to3"

I'm trying to convert a code from python 2 to python 3, that makes a request from simsimi api. Python 2 code : # -*- coding: utf- -*- import urllib import urllib2 url = "http://sandbox.api.simsimi.com/request.p?" text_input = raw_input("Input…
SoxxZ _
  • 21
  • 1
0
votes
0 answers

Conversion error when using Python 2to3

When running this cmd: 2to3 util.py -v -p -w I have this message : RefactoringTool: Adding transformation: zip RefactoringTool: Can't parse util.py: ParseError: bad input: type=1, value='f', context=(' ', (150, 11)) RefactoringTool: No changes in…
tensor
  • 3,088
  • 8
  • 37
  • 71
0
votes
2 answers

pyserial Python2/3 string headache

I'm using pyserial to communicate with some sensors which use the Modbus protocol. In Python 2.7, this works perfectly: import serial c = serial.Serial('port/address') # connect to sensor msg = "\xFE\x44\x00\x08\x02\x9F\x25" # 7 hex…
oscarbranson
  • 3,877
  • 1
  • 13
  • 15
0
votes
2 answers

Calling 2to3 in Python using cmd

I have a folder of .py files written in Python 2.7 that I want to convert to Python 3 using the 2to3 tool. Using windows 10 in the cmd prompt i can convert a single file with the following command: C:\Users\t\Desktop\search>python.exe 2to3.py -w…
Braide
  • 155
  • 3
  • 3
  • 13
0
votes
1 answer

Installing BeautifulSoup4 via pip produces an import error for Python 3.5

I'm trying to install beautifulsoup4 for Python 3.5, however, I've made it to when I call 'import bs4' to test in the Python 3.5.2 shell, I receive the error below: Traceback (most recent call last): File "", line 1, in import bs4 …
Danielson
  • 88
  • 1
  • 8
0
votes
1 answer

SSRS Get from page 2 to end page

I m rendering SSRS Report in pdf format. I want pages from 2 to Last page. Using deviceinfo is it possible?
user420054
  • 65
  • 4
  • 14
0
votes
2 answers

Python 2to3, iterating over list conditionally (filter vs list-comprehension)

I am in the process of porting a bunch of scripts from Py2 -> Py3 using the 2to3 tool. One particular suggested change confused me a bit, so I'd appreciate some help with that: The original line is: for r in filter(lambda r: r.dir == direction,…
posdef
  • 6,498
  • 11
  • 46
  • 94
0
votes
1 answer

Can't figure out how to use 2to3 Python converter

I've seen other answers for this on Stack, but they aren't helping. I have a Python 2.7 script that I need converted to work with Python 3. It seems like using 2to3 shouldn't be this difficult, but I can't figure it out. In the Windows command…
Nathan R
  • 840
  • 5
  • 13
  • 32