Skip to main content

support Python 2 with fewer warts

Project description

The future module helps run Python 3.x-compatible code under Python 2 with minimal code cruft.

The goal is to allow you to write clean, modern, forward-compatible Python 3 code today and to run it with minimal effort under Python 2 alongside a Python 2 stack that may contain dependencies that have not yet been ported to Python 3.

It is designed to be used as follows:

from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from future import *

followed by clean Python 3 code (with a few restrictions) that can run unchanged on Python 2.7.

For example:

# Supports the standard library reorganization (PEP 3108)
import socketserver
import queue
import configparser
# and other moved modules

# New range object with slicing support
for i in range(10**11)[:10]:
    pass

# Other common iterators: map, reduce, zip
my_iter = zip(range(3), ['a', 'b', 'c'])
assert iter != list(my_iter)

# New simpler super() function:
class VerboseList(list):
    def append(self, item):
        print('Adding an item')
        super().append(item)

# These raise NameErrors:
# apply(), cmp(), coerce(), reduce(), xrange(), etc.

# This identity is restored. This is normally valid on Py3 and Py2, but
# 'from __future__ import unicode_literals' breaks it on Py2:
assert isinstance('happy', str)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

future-0.1.0.tar.gz (18.9 kB view details)

Uploaded Source

File details

Details for the file future-0.1.0.tar.gz.

File metadata

  • Download URL: future-0.1.0.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for future-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f11b05b486d88dd1ea4fe48e3d3742cafdc71160eb1edbfe8032b48b908dd568
MD5 fd8a275860cfb38f2a441c0402593158
BLAKE2b-256 afcf4fbe349bcf9a08f2c329a66cc4d4a417387acc9033ad5238160b3f266e05

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page