MCPcopy Index your code
hub / github.com/tensorlayer/TensorLayer / as_bytes

Function as_bytes

tensorlayer/nlp.py:50–65  ·  view source on GitHub ↗

Converts either bytes or unicode to `bytes`, using utf-8 encoding for text. Args: bytes_or_text: A `bytes`, `str`, or `unicode` object. encoding: A string indicating the charset for encoding unicode. Returns: A `bytes` object. Raises: TypeError: If `bytes_or_text` is not a bina

(bytes_or_text, encoding='utf-8')

Source from the content-addressed store, hash-verified

48
49
50def as_bytes(bytes_or_text, encoding='utf-8'):
51 """Converts either bytes or unicode to `bytes`, using utf-8 encoding for text.
52 Args:
53 bytes_or_text: A `bytes`, `str`, or `unicode` object.
54 encoding: A string indicating the charset for encoding unicode.
55 Returns:
56 A `bytes` object.
57 Raises:
58 TypeError: If `bytes_or_text` is not a binary or unicode string.
59 """
60 if isinstance(bytes_or_text, _six.text_type):
61 return bytes_or_text.encode(encoding)
62 elif isinstance(bytes_or_text, bytes):
63 return bytes_or_text
64 else:
65 raise TypeError('Expected binary or unicode string, got %r' % (bytes_or_text, ))
66
67
68def as_text(bytes_or_text, encoding='utf-8'):

Callers 2

basic_tokenizerFunction · 0.85
initialize_vocabularyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…