MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / to_str

Function to_str

example_code/item_010.py:65–70  ·  view source on GitHub ↗
(bytes_or_str)

Source from the content-addressed store, hash-verified

63
64print("Example 3")
65def to_str(bytes_or_str):
66 if isinstance(bytes_or_str, bytes):
67 value = bytes_or_str.decode("utf-8")
68 else:
69 value = bytes_or_str
70 return value # Instance of str
71
72print(repr(to_str(b"foo")))
73print(repr(to_str("bar")))

Callers 1

item_010.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected