Skip to content

Commit 4322a1c

Browse files
committed
1 parent 355a1bf commit 4322a1c

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Lib/future_builtins.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""This module provides functions that will be builtins in Python 3.0,
2+
but that conflict with builtins that already exist in Python 2.x.
3+
4+
Functions:
5+
6+
hex(arg) -- Returns the hexadecimal representation of an integer
7+
oct(arg) -- Returns the octal representation of an integer
8+
ascii(arg) -- Same as repr(arg)
9+
map, filter, zip -- Same as itertools.imap, ifilter, izip
10+
11+
The typical usage of this module is to replace existing builtins in a
12+
module's namespace:
13+
14+
from future_builtins import hex, oct
15+
"""
16+
17+
__all__ = ['hex', 'oct', 'ascii', 'map', 'filter', 'zip']
18+
19+
from itertools import imap as map, ifilter as filter, izip as zip
20+
21+
ascii = repr
22+
_builtin_hex = hex
23+
_builtin_oct = oct
24+
25+
def hex(arg):
26+
return _builtin_hex(arg).rstrip('L')
27+
28+
def oct(arg):
29+
result = _builtin_oct(arg).rstrip('L')
30+
if result == '0':
31+
return '0o0'
32+
i = result.index('0') + 1
33+
return result[:i] + 'o' + result[i:]

0 commit comments

Comments
 (0)