4 ms·
Or until you trip over the API differences between str and bytes in Python 3 that do not exist in Python 2 (because str == bytes in Python 2). Chiefly, printf-
by py3kthrowa 11y ago
Or until you trip over the API differences between str and bytes in Python 3 that do not exist in Python 2 (because str == bytes in Python 2). Chiefly, printf-style formatting...
>>> b"%u" % 5
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for %: 'bytes' and 'int'
- Rotten194 11y agoWhy are you using % at all? It should have been deprecated years ago.
- eru 11y agoWhy? What are the benefits? % can have as much information about the string and the arguments as .format, can't it? If I remember right, % used to be deprecated in Python 3, but was undeprecated again by popular demand.
- andrepd 11y agoWhy? Maybe it suits his use case better than .format() or whatever.
- startling 11y agoIt's not deprecated, though.
- bskap 11y agoFixed as of a month ago. https://www.python.org/dev/peps/pep-0461/ https://www.python.org/dev/peps/pep-0461/
- bpicolo 11y agoThere's plenty of times it still matters. E.g. data coming in on webserver -> json.loads(foo) blahblahException foo is bytes not text. That said I still endorse py3 for new things