Skip to content

Instantly share code, notes, and snippets.

@Richienb
Created July 1, 2018 08:37
Show Gist options
  • Save Richienb/23b805a3b834a712ac29d01798f7b579 to your computer and use it in GitHub Desktop.
Save Richienb/23b805a3b834a712ac29d01798f7b579 to your computer and use it in GitHub Desktop.
Python 3 to 2 backwards compatibility with future

Backwards compatibility in Python using future

How does it work?

The future module adds support for modules supported in Python 3.x to Python 2.x

How to use it?

  1. Install future
$ pip install future
  1. Add the following code to the top of your Python 3.x files
# Backwards Compatibility
from __future__ import absolute_import, division, print_function, unicode_literals
from future import standard_library
standard_library.install_aliases()
from builtins import (bytes, dict, int, list, object, range, str, ascii, chr, hex,
                      input, next, oct, open, pow, round, super, filter, map, zip)

For more information, see the examples provided.

pip install future
# Backwards Compatibility
from __future__ import absolute_import, division, print_function, unicode_literals
from future import standard_library
standard_library.install_aliases()
from builtins import (bytes, dict, int, list, object, range, str, ascii, chr, hex,
input, next, oct, open, pow, round, super, filter, map, zip)
# Other Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment