Dennis Lee Bieber wrote:
On Thu, 1 Sep 2011 00:56:50 -0400, Sahil Tandon
# process input, line-by-line, and print responses after parsing input
while 1:
rval = parse(raw_input())
if rval == None:
There is only ONE "None" object so the preferred method is
if rval is None:
On 01Sep2011 22:02, Sahil Tandon wrote:
| [Thanks to everyone who responded]
|
| Steven D'Aprano wrote:
| >On Thu, 1 Sep 2011 02:56 pm Sahil Tandon wrote:
| >>%%
| >># unbuffer STDOUT
| >>sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
| >
| >I've never bothered with unbuffered stdout, but th
On Thu, 01 Sep 2011 16:02:54 +1000, Steven D'Aprano wrote:
> On Thu, 1 Sep 2011 02:56 pm Sahil Tandon wrote:
>> # 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'
[Thanks to everyone who responded]
Steven D'Aprano wrote:
On Thu, 1 Sep 2011 02:56 pm Sahil Tandon wrote:
%%
# unbuffer STDOUT
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
I've never bothered with unbuffered stdout, but that looks fine to me.
I'm not sure if it is necessary though, be
Sahil Tandon writes:
> I've been tasked with converting some programs from Perl -> Python, and
> am (as will soon be obvious) new to the language.
If it's any help, I have usually done handling of standard input line by
line with this kind of thing:
for inputline in sys.stdin:
--
http://mail.
Peter Otten wrote:
> A quick look into fileinput.py reveals that it uses readlines() and slurps
> in the complete "file". I'm not sure that was a clever design decision...
Correction:
>>> with open("tmp.txt") as f: lines = f.readlines(0)
...
>>> len(lines)
100
>>> with open("tmp.txt") as f:
Sahil Tandon wrote:
> 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 t
On Thu, 1 Sep 2011 02:56 pm Sahil Tandon wrote:
> 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 m
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: