Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.06; 'subject:PEP': 0.07; '[1,': 0.09; 'accepted,': 0.09; 'ascii': 0.09; 'assuming': 0.09; 'bytes,': 0.09; 'encode': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'pep': 0.09; '~ethan~': 0.09; 'python': 0.11; "%s'": 0.16; 'bytearray': 0.16; 'repr': 0.16; 'wrote:': 0.18; 'discussion': 0.18; 'obviously': 0.18; 'feb': 0.22; 'example': 0.22; 'header :User-Agent:1': 0.23; 'bytes': 0.24; 'skip:% 10': 0.24; 'mon,': 0.24; '(or': 0.24; 'header:In-Reply-To:1': 0.27; 'points': 0.29; 'code': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'subject:skip:i 10': 0.31; 'yes.': 0.31; '(i.e.': 0.33; 'something': 0.35; 'anybody': 0.35; 'convert': 0.35; 'add': 0.35; 'in:': 0.36; 'object,': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'should': 0.36; 'list': 0.37; 'handle': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'no.': 0.61; 'received:173': 0.61; 'back': 0.62; '(that': 0.65; 'debate': 0.68; 'ethan': 0.84; 'furman': 0.84; 'greetings!': 0.84; 'received:gateway15.websitewelcome.com': 0.84; 'do:': 0.91 Date: Mon, 24 Feb 2014 16:10:53 -0800 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Python 3.5, bytes, and %-interpolation (aka PEP 461) References: <530bdbe2$0$29985$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <530bdbe2$0$29985$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator3304.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-BWhitelist: no X-Source-IP: 173.12.184.233 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([173.12.184.233]) [173.12.184.233]:49755 X-Source-Auth: ethan+stoneleaf.us X-Email-Count: 1 X-Source-Cap: dG9idWs7dG9idWs7Z2F0b3IzMzA0Lmhvc3RnYXRvci5jb20= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 65 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393288494 news.xs4all.nl 2921 [2001:888:2000:d::a6]:35856 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:67009 On 02/24/2014 03:55 PM, Steven D'Aprano wrote: > On Mon, 24 Feb 2014 11:54:54 -0800, Ethan Furman wrote: > >> Greetings! >> >> A PEP is under discussion to add %-interpolation back to the bytes type >> in Python 3.5. >> >> Assuming the PEP is accepted, what *will* be added back is: >> >> Numerics: >> >> b'%d' % 10 --> b'10' >> b'%02x' % 10 --> b'0a' >> >> Single byte: >> >> b'%c' % 80 --> b'P' > > Will %c also accept a length-1 bytes object? > > b'%c' % b'x' > => b'x' Yes. >> and generic: >> >> b'%s' % some_binary_blob --> b'tHE*&92h4' (or whatever) > > Will b'%s' take any arbitrary object, as in: > > b'Key: %s' % [1, 2, 3, 4] > => b'Key: [1, 2, 3, 4]' No. > or only something which is already bytes (i.e. a bytes or bytearray > object)? It must already be bytes, or have __bytes__ method (that returns bytes, obviously ;) . >> What is under debate is whether we should also add %a: >> >> b'%a' % some_obj --> b'some_obj_repr' >> >> What %a would do: >> >> get the repr of some_obj >> >> convert it to ascii using backslashreplace (to handle any code points >> over 127) >> >> encode to bytes using 'ascii' >> >> Can anybody think of a use-case for this particular feature? > > Not me. I find that humorous, as %a would work with your list example above. :) -- ~Ethan~