k3str

k3str is a collection of string operation utilily.

>>> repr(to_bytes('我'))
"b'\\xe6\\x88\\x91'"

Functions

k3str.to_bytes(s, encoding=None)

Convert str to bytes. If it is already bytes, do nothing.

Parameters
  • s – str or bytes

  • encoding (str) – the encoding to encode str. If it is None, system default encoding is used.

Returns

bytes

k3str.to_utf8(s)

Convert str to utf8 bytes. It is an alias of to_bytes(s, encoding='utf-8').

Indices and tables