[Tutor] removing values using a loop

Sharriff Aina NHYTRO@compuserve.com
Wed, 25 Apr 2001 02:51:02 -0400


Hi List!

I retrieve strings from a database  using CGI in the format:
[('Home, None, Kontakt, Termine, None, None')]

as an example, this string varies according to the database entry made by=

the user
I=B4m trying to generate HTML from these links by splitting the big strin=
g
into singular values, my big problem is removing the  "None"s. I=B4ve tri=
ed
my best and rewrote the code at least 3 times, but my code fails and only=

works when the nones are at the end of the string, my code:


#### code start, test 1 ####
templinks =3D alllinks[0]
links =3D string.split(templinks[0],",")
for x in links:
.... if x =3D=3D "Kontakt":
........ counter =3D counter + 1
........ print "<td>%d.&nbsp;</td>" %(counter)
........ print '<td bgcolor=3D"#EDBE30">',
........ print x
........# more HTML code
....else:
........pass
###### code end #######

I=B4ve also tried:

#### code start, test 2 ####
 templinks =3D alllinks[0]
links =3D string.split(templinks[0],",")
for x in links:
....if x =3D=3D "None:
........pass
....elif  =3D=3D "Kontakt":
........ counter =3D counter + 1
........ print "<td>%d.&nbsp;</td>" %(counter)
........ print '<td bgcolor=3D"#EDBE30">',
........ print x
........# more HTML code
####  code end ####

both code snippets do not work as expected, could some one help? =

Frustrated I thought it would be a good idea to remove the "None"s  BEFOR=
E
the string is sored in the database, but that proved to be a more diffucu=
lt
task, see:

#### code start ###
# get links from form
# -------------------- =

for a in range(len(form.keys())):
....b =3D form.getvalue("link" + str(a))
....linklist.append(b)
....delimitedlinks =3D  string.join(map(str, (linklist)), ",")
cur.execute("update users set navlinks=3D'%s' where username =3D'%s'"
%(delimitedlinks,usernamevalue))
connection.commit()
cur.close()
connection.close()
#### code end ###

I have likewise written several versions of this snippet, but I end up
breaking my databse access

Please forgive my long post, I have to present an alpha of this applicati=
on
today, but I think the deadline stress and staring too long at the same
piece of code has got to me. :-(

Thank you very, very much in advance for your anticipated help.


Sharriff