<div class="gmail_quote">On Fri, Jan 8, 2010 at 3:09 PM, Victor Subervi <span dir="ltr"><<a href="mailto:victorsubervi@gmail.com">victorsubervi@gmail.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;">
<br><br><div class="gmail_quote"><div class="im">On Fri, Jan 8, 2010 at 2:52 PM, Jean-Michel Pichavant <span dir="ltr"><<a href="mailto:jeanmichel@sequans.com" target="_blank">jeanmichel@sequans.com</a>></span> wrote:<br>
</div><div><div></div><div class="h5"><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:<div><div></div><div><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Fri, Jan 8, 2010 at 1:26 PM, Steve Holden <<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>>> 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 exactly copied from a Web page tutorial. Can you folks point me to tutorials where I can learn to comprehend this code? Specifically, the line in question. How is it that one can code "params[key]" (what does that mean?) and the other side, what does that mean<br>


</blockquote></div></div>
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></blockquote></div></div><div><br>This still isn't telling me what I need to know. Perhaps I'm missing the point, as in the recent case with putting the "print cookie" statement in the header. I am assuming (translation: making an a$$ out of you and me) that "params[key] automatically assigns the fieldStorage key to the newly created params key in the dict of the same, and assigning the value from the cgi.FieldStorage of that key to the params value. Is that correct?<br>

TIA,<br>beno<br></div></div></blockquote><div><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>  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>Thanks all.<br>beno<br>
</div></div>