can you iterate over a FieldStorage object?

J

John Salerno

I'm trying to use a for loop with a FieldStorage object and I get the
following error. Can you not treat it like a dictionary, or am I writing
the for loop incorrectly?

for item in form:
print item
# or print item.value



KeyError Python 2.2.1: /usr/bin/python
Fri Jun 2 15:12:36 2006

A problem occurred in a Python script. Here is the sequence of function
calls leading up to the error, in the order they occurred.

/kunden/homepages/7/d159103796/htdocs/labinfo.py
6 print 'content-type: text/html\n'
7
8 form = cgi.FieldStorage(keep_blank_values=True)
9 for item in form:
10 print item
item undefined, form = FieldStorage(None, None,
[MiniFieldStorage('firs...02116'), MiniFieldStorage('foreignAddress', '')])

/usr/lib/python2.2/cgi.py in __getitem__(self=FieldStorage(None, None,
[MiniFieldStorage('firs...02116'), MiniFieldStorage('foreignAddress',
'')]), key=0)
548 if item.name == key: found.append(item)
549 if not found:
550 raise KeyError, key
551 if len(found) == 1:
552 return found[0]
KeyError undefined, key = 0

KeyError: 0
__doc__ = 'Mapping key not found.'
__getitem__ = <bound method KeyError.__getitem__ of
<exceptions.KeyError instance at 0x81633e4>>
__init__ = <bound method KeyError.__init__ of
<exceptions.KeyError instance at 0x81633e4>>
__module__ = 'exceptions'
__str__ = <bound method KeyError.__str__ of <exceptions.KeyError
instance at 0x81633e4>>
args = (0,)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top