def to_native_string(string, encoding="ascii"): """Given a string object, regardless of type, returns a representation of
that string in the native string type, encoding and decoding where
necessary. This assumes ASCII unless told otherwise. """ if isinstance(string, builtin_str):
out = string else:
out = string.decode(encoding)
return out
def unicode_is_ascii(u_string): """Determine if unicode string only contains ASCII characters.
:param str u_string: unicode string to check. Must be unicode andnot Python 2 `str`.
:rtype: bool """ assert isinstance(u_string, str) try:
u_string.encode("ascii") returnTrue except UnicodeEncodeError: returnFalse
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.