Web programming and a different "type" problem (was: Slice confusion : a[n:p] is a list exclude the last element p)

Ian Bicking ianb at colorstudy.com
Tue Apr 29 12:06:27 CEST 2003


On Mon, 2003-04-28 at 14:22, Cameron Laird wrote:
> 'Doesn't work, though.  Here's where the special case
> enters:  if only one datum with the indicated name is
> present as input, Zope and the others return it as a
> simple string, rather than a list with that string as 
> its sole member. 

I'm not a fan of using field names (like field:list, or field*, or
field[]), though I suppose it isn't that bad.  Without that you have the
option of a custom getter, like maybe:

valueList = request.multiple('field')

Which promotes a single string to a list, and if the value is missing
returns an empty list (which the field names don't do).

Otherwise you got to use a schema.  I made a simple schema system
recently, as I've been playing around with forms.  It's the
DictCall.(txt,py):

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/webware-sandbox/Sandbox/ianbicking/FormEncode/

It has several ways of defining simple schemas which are used to
translate a dictionary of input into a function call.  So you can do
something like:

# goto delete?id=1&id=2&id=3
def delete(id_set_int): 
    # id_set_int is a list of integers...

You could also define the schema through a function attribute or the
docstring.

Really just an experiment, but I'm still playing with the ideas.

  Ian







More information about the Python-list mailing list