compat¶
Download python-snippets-0.2.zip
compat.py - Python 2/3 compatibility
usage: | compat.py [OPTIONS] |
or | import compat |
Options¶
-q, –quiet suppress warnings -v, –verbose verbose test output -d, –debug[=NUM] show debug information -h, –help display this help message –template list show available templates. –eide[=COMM] Emacs IDE template list (implies –template list). –template[=NAME] extract named template to standard output. Default NAME is -
.–extract[=DIR] extract adhoc files to directory DIR (default: .
)–explode[=DIR] explode script with adhoc in directory DIR (default __adhoc__
)–implode implode script with adhoc -t, –test run doc tests
Module¶
PyJsMo internal import template:
>>>
_pyjsmo_loaded_ = False
try:
exec("from .compat import *")
exec("from .base import PyJsMo")
_pyjsmo_loaded_ = True
except (SyntaxError, SystemError, ValueError, ImportError):
pass
if not _pyjsmo_loaded_:
from pyjsmo.compat import *
from pyjsmo.base import PyJsMo
del(globals()['_pyjsmo_loaded_'])
Exports¶
>>> for ex in __all__:
... printf(sformat('from {0} import {1}', __name__, ex))
from compat import printf
from compat import sformat
from compat import isstring
from compat import issequence
from compat import sequence_type
from compat import UCHAR_FMT
from compat import uchar
from compat import ditems
from compat import dkeys
from compat import dvalues
from compat import xfilter
from compat import xmap
from compat import lfind
from compat import dbg_comm
from compat import dbg_twid
from compat import dbg_fwid
from compat import _canonize_module_
from compat import uc_type
from compat import ucs
from compat import u8s
from compat import nts
from compat import OrderedDict
from compat import BytesIO
from compat import StringIO
from compat import BytesIOIType
from compat import StringIOIType
from compat import filterl
from compat import printe_
-
compat.
printf
()¶ print(value, …, sep=’ ‘, end=’n’, file=sys.stdout)
Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline.
-
compat.
isstring
()¶ String, i.e. bytes or unicode.
-
compat.
issequence
()¶ Not a string. Either a sequence (aka. list, tuple), a mapping (aka. dict), or a generator (__iter__).
-
compat.
sequence_type
()¶ is_string, is_list, is_dict, is_seq = sequence_type(obj).
-
compat.
xfilter
()¶ filter(function or None, sequence) -> list, tuple, or string
Return those items of sequence for which function(item) is true. If function is None, return the items that are true. If sequence is a tuple or string, return the same type, else return a list.
-
compat.
xmap
()¶ map(function, sequence[, sequence, …]) -> list
Return a list of the results of applying the function to the items of the argument sequence(s). If more than one sequence is given, the function is called with an argument list consisting of the corresponding item of each sequence, substituting None for missing values when not all sequences have the same length. If the function is None, return a list of the items of the sequence (or a list of tuples if more than one sequence).
-
compat.
uc_type
¶ alias of
__builtin__.unicode
-
compat.
ucs
(value, charset=None)[source]¶ Convert value to unicode string using charset or UTF-8, if value is a string.
If value is not a string, or if it is already a unicode string, return it unmodified.
-
compat.
u8s
(string, encoding=None)[source]¶ Convert string to UTF-8-encoded byte string, if string is a unicode string.
If string is not a unicode string, return it unmodified.
-
compat.
nts
(string)[source]¶ Convert string to native string, if applicable.
Python2 native strings are byte strings, while Python3 native strings are unicode.
-
class
compat.
OrderedDict
(**kwds)[source]¶ Dictionary that remembers insertion order
-
classmethod
fromkeys
(S[, v]) → New ordered dictionary with keys from S.[source]¶ If not specified, the value defaults to None.
-
pop
(k[, d]) → v, remove specified key and return the corresponding[source]¶ value. If key is not found, d is returned if given, otherwise KeyError is raised.
-
popitem
() → (k, v), return and remove a (key, value) pair.[source]¶ Pairs are returned in LIFO order if last is true or FIFO order if false.
-
update
([E, ]**F) → None. Update D from mapping/iterable E and F.¶ If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
-
classmethod
-
compat.
BytesIO
()¶ StringIO([s]) – Return a StringIO-like stream for reading or writing
-
compat.
StringIO
()¶ StringIO([s]) – Return a StringIO-like stream for reading or writing
-
compat.
BytesIOIType
¶ alias of
cStringIO.StringI
-
compat.
StringIOIType
¶ alias of
cStringIO.StringI
-
compat.
filterl
()¶ filter(function or None, sequence) -> list, tuple, or string
Return those items of sequence for which function(item) is true. If function is None, return the items that are true. If sequence is a tuple or string, return the same type, else return a list.
Copyright
Copyright (C) 2017, Wolfgang Scherer, <wolfgang.scherer@gmx.de>. See the document source for conditions of use under the GNU Free Documentation License.