Skip to content

Instantly share code, notes, and snippets.

@smmaurer
Created May 23, 2019 01:23
Show Gist options
  • Save smmaurer/764ad2751e0fb2b1ddbd534f357f7f21 to your computer and use it in GitHub Desktop.
Save smmaurer/764ad2751e0fb2b1ddbd534f357f7f21 to your computer and use it in GitHub Desktop.
Python 3 migration

Notes on migrating packages from Python 2.7 to Python 2/3 cross-compatibility

General resources

Dependencies

  • check whether dependencies are already cross-compatible
  • if newer dependency versions support only Python 3, you may need to do extra testing and/or adjust how the dependencies are specified
  • e.g., Matplotlib 3.x supports only Python 3, and pip at one point was having trouble figuring out what to install for Python 2.7

Updating syntax

  • print statements: printprint() (latter is cross-version)
  • integer division: can be implicit in Python 2.7, but must be explicit in Python 3
  • unicode handled natively by the str type in python 3 (check places where you read or write data)
  • exceptions: raise Error, "error"raise Error("error") (latter is cross-version)
  • urllib: info 1, info 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment