phonenumbers.util | index phonenumbers/util.py |
Python 2.x/3.x compatibility utilities.
This module defines a collection of functions that allow the same Python
source code to be used in both Python 2.x and Python 3.x.
- prnt() prints its arguments to a file, with given separator and ending.
- to_long() creates a (long) integer object from its input parameter.
- u() allows string literals involving non-ASCII characters to be
used in both Python 2.x / 3.x, e.g. u("ā is a-with-macron")
- unicod() forces its argument to a Unicode string.
- rpr() generates a representation of a string that can be parsed in either
Python 2.x or 3.x, assuming use of the u() function above.
>>> from .util import prnt, u, rpr
>>> prnt("hello")
hello
>>> prnt("hello", "world")
hello world
>>> prnt("hello", "world", sep=":")
hello:world
>>> prnt("hello", "world", sep=":", end='!\n')
hello:world!
>>> u('ā') == u('ā')
True
>>> u('ā') == u('ā')
True
>>> a_macron = u('ā')
>>> rpr(a_macron)
"u('\\u0101')"
>>> rpr(u('abc')) == "'abc'" # In Python 2, LHS is Unicode but RHS is string
True
>>> rpr("'")
"'\\''"
Modules | ||||||
|
Classes | ||||||||||||||||||
|
Functions | ||
|
Data | ||
U_DASH = '-' U_EMPTY_STRING = '' U_PERCENT = '%' U_PLUS = '+' U_SEMICOLON = ';' U_SLASH = '/' U_SPACE = ' ' U_STAR = '*' U_TILDE = '~' U_X_LOWER = 'x' U_X_UPPER = 'X' U_ZERO = '0' |