mo-future

7.685.25166 · active · verified Thu Apr 16

mo-future is a Python library designed to simplify Python 2/3 compatibility, aiming to be easier to use than `future` or `six`. It provides a flat namespace for common compatibility types and functions. The current version is 7.685.25166, with releases indicating active development.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and use some common compatibility shims provided by mo-future. It aims to offer Python 3-like behavior for types and functions, abstracting away Python 2/3 differences with simpler top-level imports.

from mo_future import text, bytes, range, map

# Example of using Python 3-like builtins compatible with Python 2 (if applicable)
print(type(text('hello')))
print(type(bytes(b'world')))

# range and map behave like their Python 3 counterparts (returning iterators)
my_range = range(5)
print(list(my_range))

my_map = map(lambda x: x * 2, [1, 2, 3])
print(list(my_map))

# A simple compatibility check (example, not actual mo_future feature)
try:
    from urllib.request import urlopen
except ImportError:
    from urllib2 import urlopen
    print('Using urllib2 (Python 2 pattern)')
else:
    print('Using urllib.request (Python 3 pattern)')

view raw JSON →