Mike Maxwell maxwell at
Wed Sep 1 01:29:04 CEST 2004

Hallvard B Furuseth wrote:
> Mike Maxwell wrote:
>>When I invoke readline() in a for loop, why does it return a series of
>>one-char strings, rather than the full line?
>>>>>for sL in sys.stdin.readline(): print sL
> It does return a full line.  *One* line.  Then your loop iterates
> over the characters in that line.

LoL, thanks!

> Try `for sL in sys.stdin.xreadlines(): print sL'.
> Or in newer Pythons, simply `for sL in sys.stdin: print sL'.

I think I saw that, but when I tried it, I got:

	/lib/python2.3/ DeprecationWarning:
	xreadlines is deprecated; use 'for line in file'.

--which got me off on this dead end.

What I was originally trying to do, is to implement a one-liner that 
would act something like 'sed', but applying to Unicode characters.  An 
example would have a command that looked something like
i.e. delete all instances of the Unicode char U+0D0A (which you can't do 
with 'sed', at least not the version that I'm using).

The guy down the hall does these kinds of things with perl one-liners, 
but I have more dignity than to use perl...  Unfortunately, it's looking 
more and more complex to do one-liners like this in Python.  Am I 
overlooking s.t.?

	Mike Maxwell

More information about the Python-list mailing list