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
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
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
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
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
> 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
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
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
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.
Thanks Mr. Edwards, I went ahead and started using the csv reader.
Sia
--
http://mail.python.org/mailman/listinfo/python-list
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
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
>>
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
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
> 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
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
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.
17 matches
Mail list logo