Can I write an automatic "code transformer"? =)
No. str and unicode are two different types that have different goals. You should not try to replace every occurrence of a byte string with a Unicode string in either Python 2 or Python 3.
Continue to use byte strings for binary data. In particular, everything you write to a file or network socket is bytes. And use Unicode strings for text facing the user.
In the gap is a gray area of โโinternal ASCII characters, which can be equal to bytes or Unicode. In Python 2, these are usually bytes; in Python 3, usually Unicode. In this case, you can limit your Python 2.6+ code, you can mark lines with specific bytes as b'' and bytes , your lines with specific characters as u'' and unicode and use '' and str for the string "any type of string by default ".
source share