Re: splitting delimited strings

2005-06-15 Thread John Machin
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 [EMAIL >>PROTECTED] >>At-signs in the string are represented as doubled @@. > > import re _at_re = re.compile

Re: splitting delimited strings

2005-06-15 Thread Nicola Mingotti
On Thu, 16 Jun 2005 09:36:56 +1000, John Machin wrote: >> like this ? > > No, not like that. The OP said that an embedded @ was doubled. you are right, sorry :) anyway, if @@ -> @ an empty field map to what ? -- http://mail.python.org/mailman/listinfo/python-list

Re: splitting delimited strings

2005-06-15 Thread Paul McGuire
Mark - Let me weigh in with a pyparsing entry to your puzzle. It wont be blazingly fast, but at least it will give you another data point in your comparison of approaches. Note that the parser can do the string-to-int conversion for you during the parsing pass. If @rv@ and @pv@ are record type

Re: splitting delimited strings

2005-06-15 Thread Leif K-Brooks
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 [EMAIL > PROTECTED] > At-signs in the string are represented as doubled @@. >>> import re >>> _at_re = re.compile('(?>> def split_at_line(line):

Re: splitting delimited strings

2005-06-15 Thread Mark Harrison
Paul McNett <[EMAIL PROTECTED]> 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 [EMAIL > > PROTECTED] > > At-signs in the string are represented as doubled @@. > > Have you taken

Re: splitting delimited strings

2005-06-15 Thread John Machin
Nicola Mingotti wrote: > On Wed, 15 Jun 2005 23:03:55 +, Mark Harrison wrote: > > >>What's the most efficient way to process this? Failing all >>else I will split the string into characters and use a FSM, >>but it seems that's not very pythonesqe. > > > like this ? No, not like that. The

Re: splitting delimited strings

2005-06-15 Thread John Machin
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 [EMAIL > PROTECTED] > At-signs in the string are represented as doubled @@. > > What's the most efficient way to process this? Failing all > el

Re: splitting delimited strings

2005-06-15 Thread Nicola Mingotti
On Wed, 15 Jun 2005 23:03:55 +, Mark Harrison wrote: > What's the most efficient way to process this? Failing all > else I will split the string into characters and use a FSM, > but it seems that's not very pythonesqe. like this ? >>> s = "@[EMAIL PROTECTED]@@[EMAIL PROTECTED]" >>> s.split

Re: splitting delimited strings

2005-06-15 Thread Christoph Rackwitz
You could use regular expressions... it's an FSM of some kind but it's faster *g* check this snippet out: def mysplit(s): pattern = '((?:"[^"]*")|(?:[^ ]+))' tmp = re.split(pattern, s) res = [ifelse(i[0] in ('"',"'"), lambda:i[1:-1], lambda:i) for i in tmp if i.strip()]

Re: splitting delimited strings

2005-06-15 Thread Paul McNett
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 [EMAIL > PROTECTED] > At-signs in the string are represented as doubled @@. Have you taken a look at the csv module yet? No guarantees, but it m