Web programming and a different "type" problem (was: Slice confusion : a[n:p] is a list exclude the last element p)
Cameron Laird
claird at lairds.com
Mon Apr 28 15:22:19 EDT 2003
In article <UXara.22428$K35.745468 at news2.tin.it>,
Alex Martelli <aleax at aleax.it> wrote:
><posted & mailed>
.
.
.
>It's an important design principle because of human-factors considerations,
>which Koenig expresses better than I can (I really wish he would one day
>write a "Python Traps and Pitfalls" book, but he seems too busy writing
>great C++ books instead... perhaps the Python one would be too thin?-).
.
.
.
I'd be happy to contribute "FMM" (which I've never
bothered trademarking, though I've been tempted
several times.
I'm looking for an idiom. I suspect it'll interest
some of the original readers of this thread; that
vague stylistic intuition is my justification for
this hijacking.
Here's an observation: several Python-based Web
schemes (Zope's one, I know), share what I regard as
an infelicity. The punch-line is this: checkboxed
data has to treat single items different from all
other multiplicities. Pages that naturally receive
such variants as
...mypage?value=value0
...mypage?value=value1&value=value2
are interpreted as
...
valuelist = Web-scheme-function('value')
for value in valuelist:
my_process(value)
...
'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. To iterate over all checkboxed items,
therefore, in our typical Web example, one must
...
valuelist = Web-scheme-function('value')
if valuelist == str(valuelist):
valuelist = [valuelist]
for value in valuelist:
my_process(value)
...
That's certainly ugly.
What's a better way? Is there even a better way to
think about this, in terms of basic Web standards?
--
Cameron Laird <Cameron at Lairds.com>
Business: http://www.Phaseit.net
Personal: http://phaseit.net/claird/home.html
More information about the Python-list
mailing list