<div class="gmail_quote">On Fri, Jan 8, 2010 at 3:37 PM, MRAB <span dir="ltr"><<a href="mailto:python@mrabarnett.plus.com">python@mrabarnett.plus.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Victor Subervi wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">
On Fri, Jan 8, 2010 at 3:09 PM, Victor Subervi <<a href="mailto:victorsubervi@gmail.com" target="_blank">victorsubervi@gmail.com</a> <mailto:<a href="mailto:victorsubervi@gmail.com" target="_blank">victorsubervi@gmail.com</a>>> wrote:<br>
<br>
<br>
<br>
On Fri, Jan 8, 2010 at 2:52 PM, Jean-Michel Pichavant<br></div><div class="im">
<<a href="mailto:jeanmichel@sequans.com" target="_blank">jeanmichel@sequans.com</a> <mailto:<a href="mailto:jeanmichel@sequans.com" target="_blank">jeanmichel@sequans.com</a>>> wrote:<br>
<br>
Victor Subervi wrote:<br>
<br>
On Fri, Jan 8, 2010 at 1:26 PM, Steve Holden<br>
<<a href="mailto:steve@holdenweb.com" target="_blank">steve@holdenweb.com</a> <mailto:<a href="mailto:steve@holdenweb.com" target="_blank">steve@holdenweb.com</a>><br></div>
<mailto:<a href="mailto:steve@holdenweb.com" target="_blank">steve@holdenweb.com</a> <mailto:<a href="mailto:steve@holdenweb.com" target="_blank">steve@holdenweb.com</a>>>><div><div></div><div class="h5">
<br>
wrote:<br>
<br>
MRAB wrote:<br>
> Victor Subervi wrote:<br>
> [snip]<br>
>><br>
>> Code snippet:<br>
>><br>
>> def cgiFieldStorageToDict(fieldStorage):<br>
^^^^^^^^^^^^<br>
Further hint ...<br>
<br>
>> params = {}<br>
>> for key in fieldStorage.keys():<br>
>> params[key] = cgi.FieldStorage[key].value<br>
> ^^^^^^^^^^^^^^^^^^^^^<br>
> This is your problem.<br>
<br>
<br>
The problem is that I don't understand this code that I<br>
exactly copied from a Web page tutorial. Can you folks point<br>
me to tutorials where I can learn to comprehend this code?<br>
Specifically, the line in question. How is it that one can<br>
code "params[key]" (what does that mean?) and the other<br>
side, what does that mean<br>
<br>
I think you are gathering more fans Victor :)<br>
<br>
<a href="http://docs.python.org/tutorial/datastructures.html#dictionaries" target="_blank">http://docs.python.org/tutorial/datastructures.html#dictionaries</a><br>
<br>
<br>
This still isn't telling me what I need to know. Perhaps I'm missing<br>
the point, as in the recent case with putting the "print cookie"<br>
statement in the header. I am assuming (translation: making an a$$<br>
out of you and me) that "params[key] automatically assigns the<br>
fieldStorage key to the newly created params key in the dict of the<br>
same, and assigning the value from the cgi.FieldStorage of that key<br>
to the params value. Is that correct?<br>
TIA,<br>
beno<br>
<br>
<br>
I may have answered my own question. I have this:<br>
<br>
def cgiFieldStorageToDict(fieldStorage):<br>
params = {}<br>
for key in fieldStorage.keys():<br>
params[key] = fieldStorage[key].value<br>
return params<br>
<br>
</div></div></blockquote>
Which is what Recipe 81547 actually says!<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
dict = cgiFieldStorageToDict(cgi.FieldStorage())<br>
print dict<br>
<br>
which gave me this:<br>
<br>
{'store': 'products', 'cat': 'prodCat1'}<br>
<br>
which looks about right. I would have written the code like this:<br>
<br>
keys = []<br>
values = []<br>
for key, value in fieldStorage.iteritems():<br>
keys.append(key)<br>
values.append(value)<br>
params = dict(zip(keys, values))<br>
<br>
which obviously isn't as elegant. But that's what I knew. Learned another trick, I guess ;)<br>
<br>
</blockquote></div>
If that works then so should this:<br>
<br>
params = dict(fieldStorage.iteritems())</blockquote><div><br>Yeah. Thanks!<br>beno<br>
</div></div>