Python Six

six is a compatibility layer module for Python 2 and Python 3. (2 times 3 is 6.)


Installation

Install with pip.


Usage

Many modules were renamed or reorganized. six provides a single module interface to import across Python 2 and Python 3.

For example:

from six.moves import xrange       # Python 2's xrange,     Python 3's range
from six.moves import html_parser  # Python 2's HTMLParser, Python 3's html.parser
from six.moves import tkinter      # Python 2's Tkinter,    Python 3's tkinter

# and especially
from six.moves import urllib       # Python 2's urllib, urllib2, and urlparse; Python 3's urllib

six also provides functions for iteration that not only create compatibility across Python 2 and 3, but also introduce functionality to older versions. For example, Python 2.5 predates the builtin next() function.


See also

Upstream module documentation


CategoryRicottone

Python/Six (last edited 2024-02-17 16:32:38 by DominicRicottone)