[Web-SIG] Form field dictionaries

Stuart Langridge aquarius-lists at kryogenix.org
Wed Oct 29 01:21:14 EST 2003


Simon Willison spoo'd forth:
> 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']

Would it be worth having form['fieldname'] default to doing a
getfirst()? That way, if you're *expecting* a list, you can look for
one by doing form.getlist("username") and if not you just get one entry
(getfirst should possibly be getlast, but that's a different issue).
This is a bit non-discoverable, though...

sil

-- 
"Computer games don't affect kids. I mean if Pacman had affected us as
kids, we'd all be running around in a darkened room munching pills and
listening to repetitive music."
	   -- Kristian Wilson, Nintendo



More information about the Web-SIG mailing list