{
    "mode": "pydoc",
    "parameter": "past",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/pydoc/past/json",
    "generated": "2026-06-02T14:26:38Z",
    "sections": {
        "NAME": {
            "content": "past\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "past: compatibility with Python 2 from Python 3\n===============================================\n\n``past`` is a package to aid with Python 2/3 compatibility. Whereas ``future``\ncontains backports of Python 3 constructs to Python 2, ``past`` provides\nimplementations of some Python 2 constructs in Python 3 and tools to import and\nrun Python 2 code in Python 3. It is intended to be used sparingly, as a way of\nrunning old Python 2 code from Python 3 until the code is ported properly.\n\nPotential uses for libraries:\n\n- as a step in porting a Python 2 codebase to Python 3 (e.g. with the ``futurize`` script)\n- to provide Python 3 support for previously Python 2-only libraries with the\nsame APIs as on Python 2 -- particularly with regard to 8-bit strings (the\n``past.builtins.str`` type).\n- to aid in providing minimal-effort Python 3 support for applications using\nlibraries that do not yet wish to upgrade their code properly to Python 3, or\nwish to upgrade it gradually to Python 3 style.\n\n\nHere are some code examples that run identically on Python 3 and 2::\n\n>>> from past.builtins import str as oldstr\n\n>>> philosopher = oldstr(u'孔子'.encode('utf-8'))\n>>> # This now behaves like a Py2 byte-string on both Py2 and Py3.\n>>> # For example, indexing returns a Python 2-like string object, not\n>>> # an integer:\n>>> philosopher[0]\n'å'\n>>> type(philosopher[0])\n<past.builtins.oldstr>\n\n>>> # List-producing versions of range, reduce, map, filter\n>>> from past.builtins import range, reduce\n>>> range(10)\n[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n>>> reduce(lambda x, y: x+y, [1, 2, 3, 4, 5])\n15\n\n>>> # Other functions removed in Python 3 are resurrected ...\n>>> from past.builtins import execfile\n>>> execfile('myfile.py')\n\n>>> from past.builtins import rawinput\n>>> name = rawinput('What is your name? ')\nWhat is your name? [cursor]\n\n>>> from past.builtins import reload\n>>> reload(mymodule)   # equivalent to imp.reload(mymodule) in Python 3\n\n>>> from past.builtins import xrange\n>>> for i in xrange(10):\n...     pass\n\n\nIt also provides import hooks so you can import and use Python 2 modules like\nthis::\n\n$ python3\n\n>>> from past.translation import autotranslate\n>>> authotranslate('mypy2module')\n>>> import mypy2module\n\nuntil the authors of the Python 2 modules have upgraded their code. Then, for\nexample::\n\n>>> mypy2module.functakingpy2string(oldstr(b'abcd'))\n\n\nCredits\n-------\n\n:Author:  Ed Schofield, Jordan M. Adler, et al\n:Sponsor: Python Charmers Pty Ltd, Australia: http://pythoncharmers.com\n\n\nLicensing\n---------\nCopyright 2013-2019 Python Charmers Pty Ltd, Australia.\nThe software is distributed under an MIT licence. See LICENSE.txt.\n",
            "subsections": []
        },
        "PACKAGE CONTENTS": {
            "content": "builtins (package)\ntranslation (package)\ntypes (package)\nutils (package)\n",
            "subsections": []
        },
        "DATA": {
            "content": "copyright = 'Copyright 2013-2019 Python Charmers Pty Ltd'\nlicense = 'MIT'\ntitle = 'past'\n",
            "subsections": []
        },
        "VERSION": {
            "content": "0.18.2\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Ed Schofield\n",
            "subsections": []
        },
        "FILE": {
            "content": "/usr/lib/python3/dist-packages/past/init.py\n\n",
            "subsections": []
        }
    },
    "summary": "past",
    "flags": [],
    "examples": [],
    "see_also": []
}