stripping punctuation from tuples

Brian Quinlan brian at sweetapp.com
Mon Mar 19 07:36:13 CET 2001


Tuples are sequence types, like lists, and you can use the same notation to
reference their elements.

Using your example, you might want to try the following:

>>> a[10][0]
'Alan Tsang'
>>> name, = a[10] # Another alternative
>>> name
'Alan Tsang'

-----Original Message-----
From: python-list-admin at python.org
[mailto:python-list-admin at python.org]On Behalf Of Louis Luangkesorn
Sent: Sunday, March 18, 2001 7:38 PM
To: python-list at python.org
Subject: stripping punctuation from tuples


How do you strip the punctuation from tuples?  In particular, say I have
a tuple a[10] (which happened to come from a not very well designed
database)

>>> a[10]
('Alan Tsang',)

How do I get something to say 'Alan Tsang'  with out the parens or the
','

Or, what I'm really trying to do is make this so
>>>b = breakname(a[10])
>>>b[0], b[1]

'Alan','Tsang'

I've tried to do:
>>> d = split(str(a[0]))
>>> d
["('Aaron", "Fan',)"]
>>> d[0]
"('Aaron"
>>> d[1]
"Fan',)"

But that is not quite what I want.
Many thanks.
Louis
--
K Louis Luangkesorn
lluang at northwestern.edu  http://pubweb.nwu.edu/~kll560  PGP:0xF3E2D362

Whatsoever things are true, ... honest, ... just, ... pure, ... lovely,
... of good report; if there be any virtue, and if there be any praise,
think on these things.
     - motto - Northwestern University (Phil 4:8)
--
http://mail.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list