python3 str或bytes转换函数
2017-09-07 17:57
295 查看
str或bytes始终返回为str
#!/usr/bin/env python # -*- coding: utf-8 -*- def to_str(bytes_or_str): if isinstance(bytes_or_str, bytes): value = bytes_or_str.decode('utf-8') else: value = bytes_or_str return value #Instance of str
str或bytes始终返回为bytes
#!/usr/bin/env python # -*- coding: utf-8 -*- def to_str(bytes_or_str): if isinstance(bytes_or_str, str): value = bytes_or_str.encode('utf-8') else: value = bytes_or_str return value #Instance of bytes
相关文章推荐
- python socket send 函数 报错:TypeError: a bytes-like object is required, not 'str'
- python3.5 模拟UDP客户端发送数据报文,报错:TypeError: a bytes-like object is required, not 'str'
- 了解python中bytes,str和unicode的区别
- Python 读写文件 中文乱码 错误TypeError: write() argument must be str, not bytes+
- python str与bytes之间的转换
- python3.2的bytes和str数据拼接
- Python str 与 bytes 类型(Python2/3 对 str 的处理)
- Python3中内置类型bytes和str用法及byte和string之间各种编码转换
- Python 3.x Error:TypeError: a bytes-like object is required, not 'str'
- Python菜鸟晋级02----Python3的bytes与str
- python3中的str和bytes
- python基础---字符串类型str和字节类型bytes相互转化
- Python3中bytes和HexStr之间的转换
- python中Base64编码和解码:TypeError: a bytes-like object is required, not 'str'
- Python 3.x: TypeError: a bytes-like object is required, not 'str'
- python str与bytes之间的转换
- python 3.5: TypeError: a bytes-like object is required, not 'str' when writing to a file
- Python3将API返回的bytes解码为str
- Python笔记——浅析Python3中的bytes和str类型
- python str与bytes之间的转换