Re: Extract String From Enclosing Tuple



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.
.