On Sun, Jan 12, 2014 at 11:16:37PM +1000, Nick Coghlan wrote:
> > content = '\n'.join([
> > 'header',
> > 'part 2 %.3f' % number,
> > binary_image_data.decode('latin-1'),
> > utf16_string.encode('utf-16be').decode('latin-1'),
> > 'trailer']).encode('latin-1')
>
> Why are you proposing to do the *join* in text space?
In defence of that, doing the join as text may be useful if you have
additional text processing that you want to do after assembling the
whole string, but before calling encode.
Even if you intend to encode to bytes at the end, you might prefer to
work in the text domain right until just before the end:
- no need for b' prefixes;
- indexing a string returns a 1-char string, not an int;
- can use the full range of % formatting, etc.
--
Steven
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com