Newbie lists question
Michael Hall
olc at ninti.com
Wed Jul 3 22:22:22 EDT 2002
I have a problem with an HTML select box using option values that
are drawn from a MySQL database and put into a list.
This is the code that creates the list:
db = MySQLdb.connect(user="xyz",passwd="xyz",db="names_db")
c = db.cursor()
sql = "SELECT last FROM names_table"
query = c.execute(sql)
result = c.fetchall()
selectlist = []
for last in result:
#selectlist.append(last)
selectlist = selectlist + [last]
As you can see, I have tried two ways of building the list. Both seem to
produce the same result when the list is iterated through and printed,
which looks something like this:
('van Rossum',) ('Wall',) ('Lerdorf',) ('Ousterhout',)
When I pass the list to a function that creates a selectbox, my options
end up just like they are above:
<option value="('van Rossum',)">('van Rossum',)</option>
<option value="('Wall',)">('Wall',)</option>
<option value="('Lerdorf',)">('Lerdorf',)</option>
<option value="('Ousterhout',)">('Ousterhout',)</option>
What I'd like is this:
<option value="van Rossum">van Rossum</option>
<option value="Wall">Wall</option>
<option value="Lerdorf">Lerdorf</option>
<option value="Ousterhout">Ousterhout</option>
I know I could probably strip the round brackets and single quotes out
using a regex, but is there an easier way? Is there something pretty basic
about lists that I've missed here?
TIA
Michael Hall
More information about the Python-list
mailing list