Re: How to split a string containing nested commas-separated substrings

2008-06-24 Thread mario
I have actually highlighted a small neat recipe for doing such unpacking, that I use for parsing arbitrary parameters in Evoque Templating. I never needed to handle "callable" parameters though, as you do in your 3rd string example, so the little "unpack_symbol" recipe I have publiched earlier does

Re: How to split a string containing nested commas-separated substrings

2008-06-18 Thread Matimus
On Jun 18, 10:54 am, Matimus <[EMAIL PROTECTED]> wrote: > On Jun 18, 10:19 am, Robert Dodier <[EMAIL PROTECTED]> wrote: > > > > > Hello, > > > I'd like to split a string by commas, but only at the "top level" so > > to speak. An element can be a comma-less substring, or a > > quoted string, or a su

Re: How to split a string containing nested commas-separated substrings

2008-06-18 Thread Paul McGuire
On Jun 18, 12:19 pm, Robert Dodier <[EMAIL PROTECTED]> wrote: > Hello, > > I'd like to split a string by commas, but only at the "top level" so > to speak. An element can be a comma-less substring, or a > quoted string, or a substring which looks like a function call. > If some element contains com

Re: How to split a string containing nested commas-separated substrings

2008-06-18 Thread Cédric Lucantis
Hi, Le Wednesday 18 June 2008 19:19:57 Robert Dodier, vous avez écrit : > Hello, > > I'd like to split a string by commas, but only at the "top level" so > to speak. An element can be a comma-less substring, or a > quoted string, or a substring which looks like a function call. > If some element c

Re: How to split a string containing nested commas-separated substrings

2008-06-18 Thread Matimus
On Jun 18, 10:19 am, Robert Dodier <[EMAIL PROTECTED]> wrote: > Hello, > > I'd like to split a string by commas, but only at the "top level" so > to speak. An element can be a comma-less substring, or a > quoted string, or a substring which looks like a function call. > If some element contains com

How to split a string containing nested commas-separated substrings

2008-06-18 Thread Robert Dodier
Hello, I'd like to split a string by commas, but only at the "top level" so to speak. An element can be a comma-less substring, or a quoted string, or a substring which looks like a function call. If some element contains commas, I don't want to split it. Examples: 'foo, bar, baz' => 'foo' 'bar'

Re: How to Split a String

2007-11-30 Thread Siah
> I hope you don't use Python to access the database, get a tuple back, > convert it to a string and then try to break up that string into a list!? Sadly, that is the case. Well, kinda. I'm using psycopg2 to access postgresql, which is great. Though postgres has more features than psycopg2 support

Re: How to Split a String

2007-11-30 Thread Bjoern Schliessmann
Siah wrote: > The basic split/strip method wouldn't split '(a, b, "c,...", d)', > which is why I chose not to use it. Could you please explain which part of my example doesn't work? split takes arguments which enables it to split your string as desired. > The csv solution seems to work well, th

Re: How to Split a String

2007-11-30 Thread Marc 'BlackJack' Rintsch
On Thu, 29 Nov 2007 12:12:20 -0800, Siah wrote: > I need to convert the string: '(a, b, "c", d, "e")' into the following > list ['a', 'b', 'c', 'd', 'e']. Much like a csv reader does. I usually > use the split function, but this mini-monster wouldn't properly get > split up due to those random quo

Re: How to Split a String

2007-11-29 Thread imho
Grant Edwards ha scritto: >> One solution: >> > s = '(a, b, "c", d, "e")' > print [x.strip('" ') for x in s.strip('()').split(',')] >> ['a', 'b', 'c', 'd', 'e'] > > That fails when a quoted string contains commas: > s = '(a, b, "c", d, "e,f,g")' print [x.strip('" ') for x in s.

Re: How to Split a String

2007-11-29 Thread Siah
Thanks Mr. Edwards, I went ahead and started using the csv reader. Sia -- http://mail.python.org/mailman/listinfo/python-list

Re: How to Split a String

2007-11-29 Thread Grant Edwards
On 2007-11-29, Grant Edwards <[EMAIL PROTECTED]> wrote: >> One solution: >> >> >>> s = '(a, b, "c", d, "e")' >> >>> print [x.strip('" ') for x in s.strip('()').split(',')] >> ['a', 'b', 'c', 'd', 'e'] > > That fails when a quoted string contains commas: > s = '(a, b, "c", d, "e,f,g")' pr

Re: How to Split a String

2007-11-29 Thread Grant Edwards
On 2007-11-29, imho <[EMAIL PROTECTED]> wrote: > Siah ha scritto: >> Hi, >> >> I need to convert the string: '(a, b, "c", d, "e")' into the following >> list ['a', 'b', 'c', 'd', 'e']. Much like a csv reader does. I usually >> use the split function, but this mini-monster wouldn't properly get >>

Re: How to Split a String

2007-11-29 Thread Siah
The basic split/strip method wouldn't split '(a, b, "c,...", d)', which is why I chose not to use it. The csv solution seems to work well, that helped me much here (thank you), but I am looking to see if I can get it solved with some regular expression. This is how far I've come so far, but it nee

Re: How to Split a String

2007-11-29 Thread imho
Siah ha scritto: > Hi, > > I need to convert the string: '(a, b, "c", d, "e")' into the following > list ['a', 'b', 'c', 'd', 'e']. Much like a csv reader does. I usually > use the split function, but this mini-monster wouldn't properly get > split up due to those random quotations postgresql retu

Re: How to Split a String

2007-11-29 Thread Tim Chase
> I need to convert the string: '(a, b, "c", d, "e")' into the > following list ['a', 'b', 'c', 'd', 'e']. Much like a csv > reader does. I usually use the split function, but this > mini-monster wouldn't properly get split up due to those > random quotations postgresql returns to me. Uh...use the

Re: How to Split a String

2007-11-29 Thread Grant Edwards
On 2007-11-29, Siah <[EMAIL PROTECTED]> wrote: > I need to convert the string: '(a, b, "c", d, "e")' into the following > list ['a', 'b', 'c', 'd', 'e']. Much like a csv reader does. http://docs.python.org/lib/module-csv.html -- Grant Edwards grante Yow! ... the HI

Re: How to Split a String

2007-11-29 Thread Bjoern Schliessmann
Siah wrote: > I need to convert the string: '(a, b, "c", d, "e")' into the > following list ['a', 'b', 'c', 'd', 'e']. Much like a csv reader > does. I usually use the split function, but this mini-monster > wouldn't properly get split up due to those random quotations > postgresql returns to me.

How to Split a String

2007-11-29 Thread Siah
Hi, I need to convert the string: '(a, b, "c", d, "e")' into the following list ['a', 'b', 'c', 'd', 'e']. Much like a csv reader does. I usually use the split function, but this mini-monster wouldn't properly get split up due to those random quotations postgresql returns to me. Please help me wi