A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2014-January/131297.html below:

Add bytes % args and bytes.format(args) to Python 3.5

[Python-Dev] RFC: PEP 460: Add bytes % args and bytes.format(args) to Python 3.5Steven D'Aprano steve at pearwood.info
Sun Jan 12 18:36:57 CET 2014
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
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4