Garrett Berg <googb...@gmail.com> writes: > ... > However, there are times that I do not care what data I am working with, > and I find myself writing something like: > > if isinstance(data, bytes): data = data.decode()
Apparently, below this code, you do care that "data" contains "str" (not "bytes") -- otherwise, you could simply drop this line. Note, in addition, that the code above might only work if "data" actually contains ASCII only bytes (at least in Python 2.x, it would fails otherwise). To safely decode bytes into unicode, you need to precisely know the encoding -- something which is not consistent with "I do not care about what data I am working with". -- https://mail.python.org/mailman/listinfo/python-list