Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Marko Rauhamaa Newsgroups: comp.lang.python Subject: Re: Flush stdin Date: Wed, 22 Oct 2014 18:28:43 +0300 Organization: A noiseless patient Spider Lines: 53 Message-ID: <87tx2wdsyc.fsf@elektro.pacujo.net> References: <87a94rgxi5.fsf@elektro.pacujo.net> <87mw8qfhza.fsf@elektro.pacujo.net> <87h9yyf318.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="ff5cf27ef3d5b31f034d3b72bdc27a41"; logging-data="19209"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//ARel+8XFOV4gK7uhh2pv" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:QNO2Ejtc5LzxxZXgLOs23GpBtgQ= sha1:e8p53JGp/iNqpXshJNE79eDLSXY= Xref: csiph.com comp.lang.python:79449 random832@fastmail.us: > Yes, and 90% of the time, when someone says they want to "flush > stdin", what they really want to do is go to the next line after > they've sloppily read part of the line they're on (and the behavior > they are seeing that they object to is that their next read function > reads the rest of the current line). The appropriate course of action > in these cases is to actually read to the next newline and discard the > data, not to do any kind of flush. I'm not sure I have seen that. However, somewhat analogously, there are linux text utilities that read a number of lines and leave the input intact. Since you can't really effectively read lines, the utilities routinely read past the designated endpoint and then seek back to the end of the line. For example, consider this script: seq 20000 >test.dat { head -n 5 >/dev/null head -n 5 } /dev/null head -n 5 } I get: 1861 1862 1863 1864 because you can't seek back a pipe. The first "head" command has greedily read in the first 1860 lines and the second one continues where the first one left off. Marko