Problem with list assignment
Jesse Lawrence
lawrence_jesse at yahoo.ca
Thu Nov 21 10:28:12 EST 2002
I'm using the following function to retrieve the
headers from my mysql columns. I want to shed the
extra info, and just maintain the name of the column.
This might be really simple, but I can't seem to
figure out why the assigment of the headers to the
list header[] in my for loop isn't working.
Here's the function:
def mysqlFieldNames(conn):
cursor = conn.cursor()
cursor.execute ("DESCRIBE guestbook")
row = cursor.fetchall()
cursor.close()
# here's the problem area:
header = []
i = 0;
for r in row:
header[i] = r[0]
i = i + 1
return header
Now, when I just do a print r[0] in the for loop, I'm
getting exactly what I want, it's just that when I try
to assign it to header, that I get a "list assignment
index out of range" error.
Am I overlooking something?
Thanks very much,
Jesse Lawrence
______________________________________________________________________
Post your free ad now! http://personals.yahoo.ca
More information about the Python-list
mailing list