iostream-like lib?

Max Khesin max at cNOvSisiPonAtecMh.com
Thu May 15 14:09:00 EDT 2003


The trouble is that readline() reads more than i have to in the first place,
even before I call split().
I did hack it along the lines you suggested with a generator (limiting
readline() to a number of bytes and accounting for the last character being
possibly whitespace). I was just wondering if (and why not) there is/is not
direct support for whitespace-delimited input.

--
========================================
Max Khesin, software developer -
max at cNvOiSsPiAoMntech.com
[check out our image compression software at www.cvisiontech.com, JBIG2-PDF
compression @
www.cvisiontech.com/cvistapdf.html]


"Anton Muhin" <antonmuhin at sendmail.ru> wrote in message
news:ba0jm0$1uqj$1 at news.peterlink.ru...
> Max Khesin wrote:
> > It there a library in python similar to iostream in terms of reading
> > white-space delimited input? I had some files that use both ' ' and '\n'
for
> > delimiters and readlines just does not do it out of the box.
> >
> > --
> > ========================================
> > Max Khesin, software developer -
> > max at cNvOiSsPiAoMntech.com
> > [check out our image compression software at www.cvisiontech.com,
JBIG2-PDF
> > compression @
> > www.cvisiontech.com/cvistapdf.html]
> >
> >
> >
>
> I hope this helps:
>
>  >>> s = "xxx yyy\nzzz"
>  >>> print s.split()
> ['xxx', 'yyy', 'zzz']
>  >>> s = "xxx  yyy \n zzz"
>  >>> print s.split()
> ['xxx', 'yyy', 'zzz']
>  >>>
>
> So you just read lines (or the whole file, if it's small enough) and
> spilt lines. If you want to be closer to C++, you can write your iterator.
>
> anton.
>






More information about the Python-list mailing list