Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3a.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.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'value,': 0.04; 'received:134': 0.05; 'none:': 0.07; 'returned.': 0.07; 'escape': 0.09; 'indicates': 0.09; "wouldn't": 0.14; 'better:': 0.16; 'block:': 0.16; 'expects': 0.16; 'mode,': 0.16; 'non-blocking': 0.16; 'or.': 0.16; 'returned,': 0.16; 'wrote:': 0.18; 'header :User-Agent:1': 0.23; 'bytes': 0.24; 'file.': 0.24; 'header:In- Reply-To:1': 0.27; 'testing': 0.29; 'mode': 0.30; 'code': 0.31; 'says': 0.33; 'skip:d 20': 0.34; 'could': 0.34; 'subject: (': 0.35; "can't": 0.35; 'something': 0.35; 'test': 0.35; 'but': 0.35; 'consistent': 0.36; 'subject:one': 0.36; 'done': 0.36; 'too': 0.37; 'problems': 0.38; 'follows:': 0.38; 'needed': 0.38; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'around.': 0.60; 'reaching': 0.61; 'more': 0.64; 'taking': 0.65; 'close': 0.67; 'receive': 0.70; 'different.': 0.84; 'otten': 0.84; 'pardon': 0.84; 'prone': 0.91 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqIEAPLf2FOGuA9G/2dsb2JhbABZhy/Mc4McAYEnhHoBAQQBI1UGCwsYAgIFFgsCAgkDAgECAUUTCAKINgioOZE1hjIXgSyOJxaCY4FRAQSbZIcGjU2DSw Date: Wed, 30 Jul 2014 14:09:51 +0200 From: Antoon Pardon User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Icedove/24.5.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: one to many (passing variables) References: <8561innkmw.fsf@benfinney.id.au> <53D308CB.8030900@cdreimer.com> <53D8D693.9040505@rece.vub.ac.be> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1406722193 news.xs4all.nl 2923 [2001:888:2000:d::a6]:58262 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75369 On 30-07-14 13:37, Peter Otten wrote: > Antoon Pardon wrote: > >> Taking this in consideration I think the io.RawIOBase.read got it >> backwards. >> >> The documentation says the following: >> >> | If 0 bytes are returned, and size was not 0, this indicates end of file. >> | If the object is in non-blocking mode and no bytes are available, None >> | is returned. >> >> But typically if you are reading in non-blocking mode, no bytes availabe >> can be treated as if you receive an empty (byte)string. While reaching the >> end of the stream is different. So it would have been more consistent if >> an empty (byte)string was return in case of no bytes availabe and None or >> io.EOF or something like that in case of end of file. >> >> Now I have to write things as follows: >> >> for block in iter(partial(RawStream.read, 1024), ''): >> if block is not None: >> for b in block >> process(b) > or > > for block in ...: > for b in block or (): > process(b) No it obscures what is going on and is prone to problems if you have more code that expects block to be a (byte)string. I think this is better: for block in ...: block = block or '' for b in block: process(b) do_other_stuff_with(block) It is not that big a deal but you can't escape testing for an exceptional value, whether you do it with an if or with an or. A test that wouldn't be needed if they had done it the other way around. IMO they stayed too close to how things are done in C. >> Otherwise I could write it more as follows: >> >> for block in iter(partial(RawStream.read, 1024), io.EOF): >> for b in block >> process(b) >