iostream-like lib?

Anton Muhin antonmuhin at sendmail.ru
Thu May 15 13:44:32 EDT 2003


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