[Web-SIG] Form field dictionaries

Simon Willison cs1spw at bath.ac.uk
Fri Oct 24 12:37:06 EDT 2003

Gregory Collins wrote:
>>I think this is adequately addressed in the FieldStorage starting with
>>Python 2.2 with getfirst() and getlist():
> I agree, I think this is the appropriate solution; I'd rather see all
> the typechecking pushed down into the library function rather than
> being exposed to the programmer. If the argument I'm looking for
> doesn't make sense as a list then I wouldn't care if it was given
> twice; if I'm expecting something to be a list then I'd want it to be
> a list even if it were empty or singleton.

The vast majority of data sent from forms coems in as simple name/value 
pairs, which are crying out to be accessed from a dictionary. This is my 
problem with the current FieldStorage() class - it forces you to write 
code like this:

username = form.getfirst("username", "")

When code like this is far more intuitive:

username = form['username']

The extended syntax is there to deal with the very rare case of multiple 
dataa arriving for the same key. Is it really worth doubling the length 
of the code needed to access the form variables for the sake of a very 
rare edge case? This is why I'd prefer to find an alternative solution.

Simon Willison
Web development weblog: http://simon.incutio.com/

More information about the Web-SIG mailing list