Re: split CSV fields

2006-11-16 Thread John Machin
Fredrik Lundh wrote: > John Machin wrote: > > > Given Peter Otten's post, looks like > > (1) there's a bug in the "fmtparam" mechanism -- it's ignoring the > > escapechar in my first twiddle, which should give the same result as > > Peter's. > > (2) > > | >>> csv.excel.doublequote > > True > > Acc

Re: split CSV fields

2006-11-16 Thread Peter Otten
John Machin wrote: > | >>> s='"123","a,b,\"c\"",5.640' Note how I fixed the input: >>> '"123","a,b,\"c\"",5.640' '"123","a,b,"c"",5.640' >>> '"123","a,b,\\"c\\"",5.640' '"123","a,b,\\"c\\"",5.640' Peter -- http://mail.python.org/mailman/listinfo/python-list

Re: split CSV fields

2006-11-16 Thread John Machin
John Machin wrote: > John Machin wrote: > > Fredrik Lundh wrote: > > > robert wrote: > > > > > > > What is a most simple expression for splitting a CSV line > > > > with "-protected fields? > > > > > > > > s='"123","a,b,\"c\"",5.640' > > > > > > import csv > > > > > > the preferred way is to read

Re: split CSV fields

2006-11-16 Thread Fredrik Lundh
John Machin wrote: > Given Peter Otten's post, looks like > (1) there's a bug in the "fmtparam" mechanism -- it's ignoring the > escapechar in my first twiddle, which should give the same result as > Peter's. > (2) > | >>> csv.excel.doublequote > True > According to my reading of the docs: > """ >

Re: split CSV fields

2006-11-16 Thread John Machin
John Machin wrote: > Fredrik Lundh wrote: > > robert wrote: > > > > > What is a most simple expression for splitting a CSV line > > > with "-protected fields? > > > > > > s='"123","a,b,\"c\"",5.640' > > > > import csv > > > > the preferred way is to read the file using that module. if you insist

Re: split CSV fields

2006-11-16 Thread John Machin
Fredrik Lundh wrote: > robert wrote: > > > What is a most simple expression for splitting a CSV line > > with "-protected fields? > > > > s='"123","a,b,\"c\"",5.640' > > import csv > > the preferred way is to read the file using that module. if you insist > on processing a single line, you can do

Re: split CSV fields

2006-11-16 Thread Peter Otten
robert wrote: > What is a most simple expression for splitting a CSV line with "-protected > fields? > > s='"123","a,b,\"c\"",5.640' >>> import csv >>> class mydialect(csv.excel): ... escapechar = "\\" ... >>> csv.reader(['"123","a,b,\\"c\\"",5.640'], dialect=mydialect).next() ['123', 'a,b,"

Re: split CSV fields

2006-11-16 Thread Diez B. Roggisch
robert wrote: > What is a most simple expression for splitting a CSV line with "-protected > fields? > > s='"123","a,b,\"c\"",5.640' Use the csv-module. It should have a dialect for this, albeit I'm not 100% sure if the escaping of the " is done properly from csv POV. Might be that it requires e

Re: split CSV fields

2006-11-16 Thread Fredrik Lundh
robert wrote: > What is a most simple expression for splitting a CSV line > with "-protected fields? > > s='"123","a,b,\"c\"",5.640' import csv the preferred way is to read the file using that module. if you insist on processing a single line, you can do cols = list(csv.reader([string]

Re: split CSV fields

2006-11-16 Thread irfan . habib
s.split(','); robert wrote: > What is a most simple expression for splitting a CSV line with "-protected > fields? > > s='"123","a,b,\"c\"",5.640' -- http://mail.python.org/mailman/listinfo/python-list

split CSV fields

2006-11-16 Thread robert
What is a most simple expression for splitting a CSV line with "-protected fields? s='"123","a,b,\"c\"",5.640' -- http://mail.python.org/mailman/listinfo/python-list