How to define a bytes literal in Python 2.x for porting to Python 3.x using 2to3?

Baptiste Lepilleur baptiste.lepilleur at gmail.com
Sat Jan 1 04:08:50 EST 2011


Hi,

I'm trying to port some network protocol library to Python 3.x, and it
defines many bytes literals as plain string.



How do you define bytes literals so that the library can be ported to Python
3.x using only 2to3? For example:



In python 2.x, I need:

self.buffer = '\n'



In python 3.x, I need:

self.buffer = b'\n'



Is there a way to mark string literals so that 2to3 automatically prefixes
them with 'b'? Is there a simpler trick?



Baptiste.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110101/a4d8d206/attachment.html>


More information about the Python-list mailing list