Aliases:
tf.compat.as_bytes
tf.compat.as_str
tf.compat.as_bytes
tf.compat.as_str
as_bytes(
bytes_or_text,
encoding='utf-8'
)
Defined in tensorflow/python/util/compat.py
.
Converts either bytes or unicode to bytes
, using utf-8 encoding for text.
将字节或unicode转换为字节,使用utf - 8编码文本。
例子:
for line in f: #读取某个文件的每一行
line = tf.compat.as_bytes(line)
Args:
bytes_or_text
: A bytes
, str
, or unicode
object.encoding
: A string indicating the charset for encoding unicode. A bytes
object.