splitting delimited strings

John Machin sjmachin at lexicon.net
Thu Jun 16 03:36:11 CEST 2005


Leif K-Brooks wrote:
> 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 @@.
> 
> 
>>>>import re
>>>>_at_re = re.compile('(?<!@)@(?!@)')
>>>>def split_at_line(line):
> 
> ...     return [field.replace('@@', '@') for field in
> ...                               _at_re.split(line)]
> ...
> 
>>>>split_at_line('foo at bar@@baz at qux')
> 
> ['foo', 'bar at baz', 'qux']

The plot according to the OP was that the @s were quotes, NOT delimiters.



More information about the Python-list mailing list