Skip to content

ensure_str for idempotent conversion of bytes to string #6

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions