cgi getlist() problem (my first python program)

Gobo Borz goboborz at yahoo.com
Fri Jun 20 10:57:29 EDT 2003


Thank Alan and everyone. It's good to have a forum where people like you 
and Max M and John J. Lee, and countless others take the time to help 
Python newbees like me.

--Gobo

Alan Kennedy wrote:
> 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.
> 





More information about the Python-list mailing list