On 24 February 2014 08:56, Cameron Simpson <c...@zip.com.au> wrote: > On 23Feb2014 22:56, Victor Stinner <victor.stin...@gmail.com> wrote: >> > An aid to debugging -- need to see what's what at that moment? Toss it >> > into %a. It is not intended for production code, but is included to >> > hopefully circumvent the inappropriate use of __bytes__ methods on classes. >> >> How do you plan to use this output? Write it into a socket or a file? >> When I debug, I use print & logging which both expect text string. So I >> think that b'%a' is useless. > > The case from the email thread, which I support at +0.5 or maybe > only +0.1, is printing to a binary log. The classic example that > comes to mind is syslog packets.
We actually hit a bug related to that in Beaker not that long ago - we were interpolating (Python 2) 8-bit strings directly into the syslog data, and it corrupted the log message when one of those strings contained a NULL value. Would leaving %a out destroy the utility of the PEP? No. Is leaving it in useful? I think so, yes, as it provides OOWTD interpolation of pure ASCII representations into binary formats that contain ASCII compatible segments, and it's directly analogous to the handling of the numeric formatting codes with (b"%a" % obj) being a shorthand for (b"%s" % ("%a" % obj).encode("ascii")). (Note that invoking repr() or ascii() on a bytes instance is perfectly legal, even under -b and -bb - it's only str() that triggers a warning or error) Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com