On Mon, Apr 6, 2009 at 8:26 AM, AdamC <kab...@gmail.com> wrote: > 2009/4/6 Kent Johnson <ken...@tds.net>: >> On Mon, Apr 6, 2009 at 3:30 AM, AdamC <kab...@gmail.com> wrote: >>> I'm writing a small cgi application for children to use and I want to >>> check that the name they enter isn't a swear word. >> >>> #for i in swearlist: # shows swear list OK >>> # print i; >> >> Perhaps the words in swearlist include some whitespace? Try >> for i in swearlist: >> print repr(i) >> >> and look for leading and trailing spaces, tabs, etc. >> >> Kent > > I think you're on to something here Kent. Thanks. There doesn't appear > to be any whitespaces in the words but an entry in the list appears > like this: > > print swearlist[0] > returns > ('xxxx',) > > where xxxx is the expletive in the database.
Ah, yes, the result of mycursor.fetchone() is a tuple containing the fetched elements. Even though you are only reading one field, it is still returned in a tuple. That is what the parentheses and comma signify. Try this: swearlist = [] for i in range (0, myrowcount): myrow = mycursor.fetchone() swearlist.append(myrow[0]) Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor