cgi getlist() problem (my first python program)
Alan Kennedy
alanmk at hotmail.com
Fri Jun 20 10:39:38 EDT 2003
Alan Kennedy wrote:
>> One way to approach the problem is by numbering the fields in your
>> HTML form
Gobo Borz wrote:
> I didn't want to use this approach because I thought I would have to use
> eval() or something like that on the server side to build the field name
> during iteration.
You don't need to use eval. You could just extract the numeric part and
turn that into an integer, for example using regular expressions:
import re
s = "name123"
pattern = re.compile("name([0-9]+)") # Pedants go bother someone else ;-)
match = re.search(pattern, s)
if match:
print "Your number is %d" % int(match.group(1))
> Maybe there's an easier way in Python to iterate
> through a list of names like this,
Yes, there is. Max M wrote it in another message (and a nice solution it is too,
Max). That's probably the way to go.
Best of luck.
--
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/mailto/alan
More information about the Python-list
mailing list