Re: Extract String From Enclosing Tuple
- From: attn.steven.kuo@xxxxxxxxx
- Date: 28 Feb 2007 13:33:56 -0800
On Feb 28, 12:40 pm, rshep...@xxxxxxxxxxxxxxxxxxxxxx wrote:
I'm a bit embarrassed to have to ask for help on this, but I'm not finding
the solution in the docs I have here.
Data are assembled for writing to a database table. A representative tuple
looks like this:
('eco', "(u'Roads',)", 0.073969887301348305)
Pysqlite doesn't like the format of the middle term:
pysqlite2.dbapi2.InterfaceError: Error binding parameter 1 - probably
unsupported type.
I want to extract the 'Roads', part from the double-quoted enclosing
tuple.
(snipped)
Perhaps something like:
(u'Roads',)t = ('eco', "(u'Roads',)", 0.073969887301348305)
t2 = eval(t[1], { '__builtins__' : {} }, {} )
t2
'Roads't2[0].encode('ascii')
('eco', 'Roads', 0.073969887301348305)import itertools
tuple(itertools.chain((t[0], t2[0].encode('ascii')), t[2:]))
('eco', ('Roads',), 0.073969887301348305)tuple(itertools.chain((t[0], (t2[0].encode('ascii'),)), t[2:]))
--
Hope this helps,
Steven
.
- References:
- Extract String From Enclosing Tuple
- From: rshepard
- Extract String From Enclosing Tuple
- Prev by Date: Re: finding out the precision of floats
- Next by Date: RE: Python Source Code Beautifier
- Previous by thread: Re: Extract String From Enclosing Tuple
- Next by thread: Re: Extract String From Enclosing Tuple
- Index(es):