splitting delimited strings

Paul McNett p at ulmcnett.com
Thu Jun 16 01:14:04 CEST 2005

Mark Harrison wrote:
> What is the best way to process a text file of delimited strings?
> I've got a file where strings are quoted with at-signs, @like this at .
> At-signs in the string are represented as doubled @@.

Have you taken a look at the csv module yet? No guarantees, but it may 
just work. You'd have to set delimiter to ' ' and quotechar to '@'. You 
may need to manually handle the double-@ thing, but why don't you see 
how close you can get with csv?

> @rv@ 2 @db.locks@ @//depot/hello.txt@ @mh@ @mh@ 1 1 44
> @pv@ 0 @db.changex@ 44 44 @mh@ @mh@ 1118875308 0 @ :@@: :@@@@: @
> (this is from a perforce journal file, btw)

Paul McNett

More information about the Python-list mailing list