tf.compat.as_text
Stay organized with collections
Save and categorize content based on your preferences.
Converts any string-like python input types to unicode.
tf.compat.as_text(
bytes_or_text, encoding='utf-8'
)
Returns the input as a unicode string. Uses utf-8 encoding for text
by default.
Args |
bytes_or_text
|
A bytes , str , or unicode object.
|
encoding
|
A string indicating the charset for decoding unicode.
|
Returns |
A unicode (Python 2) or str (Python 3) object.
|
Raises |
TypeError
|
If bytes_or_text is not a binary or unicode string.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.compat.as_text\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/compat/as_text) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.1.0/tensorflow/python/util/compat.py#L90-L111) |\n\nConverts any string-like python input types to unicode.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf.compat.as_str`](/api_docs/python/tf/compat/as_str)\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.compat.as_str`](/api_docs/python/tf/compat/as_str), [`tf.compat.v1.compat.as_text`](/api_docs/python/tf/compat/as_text)\n\n\u003cbr /\u003e\n\n tf.compat.as_text(\n bytes_or_text, encoding='utf-8'\n )\n\nReturns the input as a unicode string. Uses utf-8 encoding for text\nby default.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------------|-------------------------------------------------------|\n| `bytes_or_text` | A `bytes`, `str`, or `unicode` object. |\n| `encoding` | A string indicating the charset for decoding unicode. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `unicode` (Python 2) or `str` (Python 3) object. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|-------------|-------------------------------------------------------|\n| `TypeError` | If `bytes_or_text` is not a binary or unicode string. |\n\n\u003cbr /\u003e"]]