follow-up to FieldStorage

J

John Salerno

If I want to get all the values that are entered into an HTML form and
write them to a file, is there some way to handle them all at the same
time, or must FieldStorage be indexed by each specific field name?
 
B

Bruno Desthuilliers

John Salerno a écrit :
If I want to get all the values that are entered into an HTML form and
write them to a file, is there some way to handle them all at the same
time, or must FieldStorage be indexed by each specific field name?

AFAIK, FieldStorage is a somewhat dict-like object, but I'm not sure it
supports the whole dict interface. At least, it does support keys(), so
you should get by with:

for k in fs.keys():
print >> myfile, k, ":", fs[k]

But reading the doc may help...
 
J

John Salerno

Bruno said:
John Salerno a écrit :
If I want to get all the values that are entered into an HTML form and
write them to a file, is there some way to handle them all at the same
time, or must FieldStorage be indexed by each specific field name?

AFAIK, FieldStorage is a somewhat dict-like object, but I'm not sure it
supports the whole dict interface. At least, it does support keys(), so
you should get by with:

for k in fs.keys():
print >> myfile, k, ":", fs[k]

But reading the doc may help...

Thanks. The cgi docs don't seem to get into too much detail, unless I
wasn't thorough enough. But your method seems like it might work well if
I can't find something after another read through.
 
T

Tim Roberts

John Salerno said:
Bruno said:
John Salerno a écrit :
If I want to get all the values that are entered into an HTML form and
write them to a file, is there some way to handle them all at the same
time, or must FieldStorage be indexed by each specific field name?

AFAIK, FieldStorage is a somewhat dict-like object, but I'm not sure it
supports the whole dict interface. At least, it does support keys(), so
you should get by with:

for k in fs.keys():
print >> myfile, k, ":", fs[k]

But reading the doc may help...

Thanks. The cgi docs don't seem to get into too much detail, unless I
wasn't thorough enough. But your method seems like it might work well if
I can't find something after another read through.

On the other hand, 45 seconds with the source code shows that "class
FieldStorage" has member functions called "keys()" and "has_key()".

Use the source, Luke. To me, that's one of the big beauties of Python.
 
B

bruno at modulix

Tim said:
Bruno said:
John Salerno a écrit :

If I want to get all the values that are entered into an HTML form and
write them to a file, is there some way to handle them all at the same
time, or must FieldStorage be indexed by each specific field name?

AFAIK, FieldStorage is a somewhat dict-like object, but I'm not sure it
supports the whole dict interface. At least, it does support keys(), so
you should get by with:

for k in fs.keys():
print >> myfile, k, ":", fs[k]

But reading the doc may help...

Thanks. The cgi docs don't seem to get into too much detail, unless I
wasn't thorough enough. But your method seems like it might work well if
I can't find something after another read through.


On the other hand, 45 seconds with the source code shows that "class
FieldStorage" has member functions called "keys()" and "has_key()".

Use the source, Luke. To me, that's one of the big beauties of Python.

FWIW, reading the source is not even needed to know this:

Python 2.4.3 (#1, Jun 3 2006, 17:26:11)
[GCC 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.['FieldStorageClass', '_FieldStorage__write', '__contains__', '__doc__',
'__getattr__', '__getitem__', '__init__', '__iter__', '__len__',
'__module__', '__repr__', 'bufsize', 'getfirst', 'getlist', 'getvalue',
'has_key', 'keys', 'make_file', 'read_binary', 'read_lines',
'read_lines_to_eof', 'read_lines_to_outerboundary', 'read_multi',
'read_single', 'read_urlencoded', 'skip_lines']
 
G

Gerard Flanagan

John said:
Bruno said:
John Salerno a écrit :
If I want to get all the values that are entered into an HTML form and
write them to a file, is there some way to handle them all at the same
time, or must FieldStorage be indexed by each specific field name?

AFAIK, FieldStorage is a somewhat dict-like object, but I'm not sure it
supports the whole dict interface. At least, it does support keys(), so
you should get by with:

for k in fs.keys():
print >> myfile, k, ":", fs[k]

But reading the doc may help...

Thanks. The cgi docs don't seem to get into too much detail, unless I
wasn't thorough enough. But your method seems like it might work well if
I can't find something after another read through.

this any use:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81547

?

Gerard
 
J

John Salerno

Gerard said:
John said:
Bruno said:
John Salerno a écrit :
If I want to get all the values that are entered into an HTML form and
write them to a file, is there some way to handle them all at the same
time, or must FieldStorage be indexed by each specific field name?
AFAIK, FieldStorage is a somewhat dict-like object, but I'm not sure it
supports the whole dict interface. At least, it does support keys(), so
you should get by with:

for k in fs.keys():
print >> myfile, k, ":", fs[k]

But reading the doc may help...
Thanks. The cgi docs don't seem to get into too much detail, unless I
wasn't thorough enough. But your method seems like it might work well if
I can't find something after another read through.

this any use:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81547

?

Gerard
Very interesting!
 
F

Fredrik Lundh

bruno said:
FWIW, reading the source is not even needed to know this:

not to mention:
Help on class FieldStorage in module cgi:

class FieldStorage
| Store a sequence of fields, reading multipart/form-data.
|
| This class provides naming, typing, files stored on disk, and
| more. At the top level, it is accessible like a dictionary, whose
| keys are the field names. (Note: None can occur as a field name.)

(followed by a detailed description of the field objects, and
descriptions of all methods on the dictionary-list object).

</F>
 

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
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top