记-python中TypeError: a bytes-like object is required, not 'str'和TypeError: must be str, not bytes with sys.stdout.write()

在python中跟其他语言一样,有的情景参数需要传递字符串,有的情景参数需要二进制bytes,转换他们之间的关系需要用到

1、转换为二进制bytes需要用到的是encode('utf-8'),用法为:str.encode('utf-8')

2、转化为字符串需要用到decode('utf-8'),用法为obj.decode('utf-8')

posted @ 2019-07-30 09:02  leon-chan  阅读(355)  评论(0编辑  收藏  举报