Skip to content

ensure_str for idempotent conversion of bytes to string #6

@jlevy

Description

@jlevy

Something like

def ensure_str(bytes_or_str, encoding=None):
  return bytes.decode(encoding) if type(bytes_or_str) is bytes else bytes_or_str

It doesn't seem like there's any single expression to do this normally.
https://stackoverflow.com/questions/7585435/best-way-to-convert-string-to-bytes-in-python-3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions