jlevy / jlevy/strif

ensure_str for idempotent conversion of bytes to string

Open
#6 0 comments 0 reactions 0 assignees View on GitHub
feature
Dominant language
Python
Stars
131
Forks
12
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.