我有预期的代码,str但将处理bytes以下列方式传递的情况:
str
bytes
if isinstance(data, bytes): data = data.decode()
不幸的是,这不适用于bytearray.有没有测试对象是否可以是一个更通用的方法bytes或bytearray,或者我应该检查这两个?是否hasattr('decode')像我觉得的那样糟糕?
bytearray
hasattr('decode')
python python-3.x
python ×1
python-3.x ×1