logo

Python 2 to 3

Last Updated: 2022-04-04

StringIO and BytesIO

The StringIO and cStringIO modules are gone. Instead, import the io module and use io.StringIO or io.BytesIO for text and data respectively.

Start a Server

Python 2

python -m SimpleHTTPServer 8000

Python 3

python3 -m http.server

String maketrans

Python 2

maketrans() is a method in string module, so you need to import it first:

import string

table = string.maketrans("from", "to")

Python 3

maketrans() is part of either bytes or str:

  • str.maketrans(from, to)
  • bytes.maketrans(from, to)