type hinted bytesconverter
This commit is contained in:
parent
9575352e3e
commit
68678177ed
@ -1,12 +1,14 @@
|
|||||||
def str_to_bytes(data):
|
def str_to_bytes(data: str) -> bytes:
|
||||||
'''Converts a string to bytes with .encode()'''
|
'''Convert a string to bytes with .encode(), utf8'''
|
||||||
try:
|
try:
|
||||||
data = data.encode('UTF-8')
|
data = data.encode('UTF-8')
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def bytes_to_str(data):
|
|
||||||
|
def bytes_to_str(data: bytes) -> str:
|
||||||
|
"""Convert bytes to strings with .decode(), utf8"""
|
||||||
try:
|
try:
|
||||||
data = data.decode('UTF-8')
|
data = data.decode('UTF-8')
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
Loading…
Reference in New Issue
Block a user