Re: Extract String From Enclosing Tuple
- From: Bruno Desthuilliers <bdesth.quelquechose@xxxxxxxxxxxxxxxxxxx>
- Date: Wed, 28 Feb 2007 22:19:32 +0100
rshepard@xxxxxxxxxxxxxxxxxxxxxx a écrit :
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. The unicode part should be automatically removed when the string is
printed, but I suspect it's the double quotes and extra parentheses that are
the problem. I know that tuples are immutable, but I thought that I could
slice it. If so, I'm not doing it correctly, because each attempt results in
TypeError: unsubscriptable object
Where do you get your data from ? MHO is that you'd better handle the problem at the source (ie : dont put a string representation of a tuple in your data) instead of trying to fix it afterward.
.
- References:
- Extract String From Enclosing Tuple
- From: rshepard
- Extract String From Enclosing Tuple
- Prev by Date: Re: How to check for remaining hard drive space in Windows?
- Next by Date: Re: class declaration shortcut
- Previous by thread: Extract String From Enclosing Tuple
- Next by thread: Re: Extract String From Enclosing Tuple
- Index(es):