Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12547
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed10.multikabel.net!feeder2.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <sahil@tandon.net> |
| 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; 'python,': 0.01; 'else:': 0.03; 'discussions': 0.03; ':-)': 0.06; 'subject:while': 0.07; 'typed': 0.07; 'python': 0.08; 'disable': 0.09; 'none:': 0.09; 'parsing': 0.09; 'debugging': 0.13; 'converting': 0.15; "'w',": 0.16; 'approach,': 0.16; 'buffering': 0.16; 'construct.': 0.16; 'input,': 0.16; 'reply-to:addr:python-list': 0.16; 'stdout': 0.16; 'sys.stdout': 0.16; 'tasked': 0.16; 'thanks,': 0.18; 'perl': 0.18; 'appears': 0.20; 'wonder': 0.23; 'missed': 0.24; 'command': 0.24; 'input': 0.24; 'language.': 0.28; 'print': 0.29; 'script': 0.29; 'does': 0.32; 'there': 0.33; 'to:addr:python-list': 0.33; "i've": 0.34; 'header:User-Agent:1': 0.34; '(as': 0.34; 'consensus': 0.34; 'reply-to:addr:python.org': 0.34; 'searches': 0.34; 'totally': 0.35; 'charset:us-ascii': 0.36; 'using': 0.37; 'but': 0.37; 'received:org': 0.38; 'some': 0.38; 'subject:: ': 0.39; 'ok,': 0.39; 'recommended': 0.39; 'to:addr:python.org': 0.39; 'received:68': 0.40; 'more': 0.60; 'your': 0.61; 'skip:o 30': 0.63; 'link': 0.63; 'free': 0.63; 'believe': 0.65; 'taking': 0.66; 'works,': 0.68; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.71; 'soon': 0.72; 'gentle': 0.77 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/simple; d=tandon.net; h= user-agent:content-disposition:content-type:content-type :mime-version:reply-to:message-id:subject:subject:from:from:date :date:received:received; s=aegis; t=1314853042; bh=foUeaKHDb2FCD zo6htuYNCM70keNCKnXpdQs1xhXvAk=; b=OWojHiDZHY3brwYBkhHuYic0i4g4B sZBDfdyv+emKgcoENt0WhXwFUH7BtbpvQHonXj8MDsmpIXMF6IkfydeVdcNT2616 6HxYrOxt8dK+WXnAeqzGt8IE2AkhOvo3Fk0570uE2HdvvzAsPNZiWOOoCUAf9xTg zdWV89oimPngXE= |
| X-Virus-Scanned | by ClamAV at spartan.hamla.org |
| Date | Thu, 1 Sep 2011 00:56:50 -0400 |
| From | Sahil Tandon <sahil@FreeBSD.org> |
| To | python-list@python.org |
| Subject | idiomatic analogue of Perl's: while (<>) { ... } |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Disposition | inline |
| User-Agent | Mutt/1.5.21 (2010-09-15) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| Reply-To | python-list@python.org |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.644.1314853527.27778.python-list@python.org> (permalink) |
| Lines | 33 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1314853527 news.xs4all.nl 2507 [2001:888:2000:d::a6]:32849 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:12547 |
Show key headers only | View raw
I've been tasked with converting some programs from Perl -> Python, and
am (as will soon be obvious) new to the language. A few archive/google
searches were inconclusive on a consensus approach, which is OK, but I
just wonder if there is a more Python-esque way to do the following in
Python 2.7.1:
%%
# unbuffer STDOUT
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
# process input, line-by-line, and print responses after parsing input
while 1:
rval = parse(raw_input())
if rval == None:
print('foo')
else:
print('bar')
%%
This works, but while reading the documentation, I thought of using 'for
line in fileinput.input()' in lieu of 'while 1:' construct. This does
not work when debugging the program on the command line -- the script
appears to just hang no matter what is typed into STDIN. I believe this
is because of some internal buffering when using fileinput. Is there a
recommended way to disable such buffering? Am I taking a totally wrong
approach?
Feel free to just link me to previous discussions on the topic(s) if I
have missed them. Please be gentle with your cluebats. :-)
Thanks,
--
Sahil Tandon <sahil@FreeBSD.org>
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
idiomatic analogue of Perl's: while (<>) { ... } Sahil Tandon <sahil@FreeBSD.org> - 2011-09-01 00:56 -0400
Re: idiomatic analogue of Perl's: while (<>) { ... } Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-09-01 16:02 +1000
Re: idiomatic analogue of Perl's: while (<>) { ... } Sahil Tandon <sahil@FreeBSD.org> - 2011-09-01 22:02 -0400
Re: idiomatic analogue of Perl's: while (<>) { ... } Dan Sommers <dan@tombstonezero.net> - 2011-09-02 02:32 +0000
Re: idiomatic analogue of Perl's: while (<>) { ... } Anssi Saari <as@sci.fi> - 2011-09-01 18:25 +0300
csiph-web