Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #11691

Re: CGI: Assign FieldStorage values to variables

References <92d066ff-d0ee-432f-b512-1f2fa01ba681@a12g2000yqi.googlegroups.com> <bd2e169b-6bcb-4578-ac49-5fba344aa150@y16g2000yqh.googlegroups.com>
Date 2011-08-17 09:23 -0700
Subject Re: CGI: Assign FieldStorage values to variables
From Chris Rebert <clp2@rebertia.com>
Newsgroups comp.lang.python
Message-ID <mailman.134.1313598183.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Aug 17, 2011 at 2:19 AM, Gnarlodious <gnarlodious@gmail.com> wrote:
> I should add that this does what I want, but something a little more
> Pythonic?
>
> import cgi, os
> os.environ["QUERY_STRING"] = "name1=Val1&name2=Val2&name3=Val3"
> form=cgi.FieldStorage()
>
> form
>
> dict = {}
> for key in form.keys(): dict[ key ] = form[ key ].value
>
> dict
> locals().update(dict)
> name3

Try it within a function. It will fail epic-ly in CPython and most
other implementations.
Read the note in the locals() docs:
http://docs.python.org/library/functions.html#locals

Cheers,
Chris

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

CGI: Assign FieldStorage values to variables Gnarlodious <gnarlodious@gmail.com> - 2011-08-17 02:06 -0700
  Re: CGI: Assign FieldStorage values to variables Gnarlodious <gnarlodious@gmail.com> - 2011-08-17 02:19 -0700
    Re: CGI: Assign FieldStorage values to variables Chris Angelico <rosuav@gmail.com> - 2011-08-17 10:41 +0100
    Re: CGI: Assign FieldStorage values to variables Chris Rebert <clp2@rebertia.com> - 2011-08-17 09:23 -0700
  Re: CGI: Assign FieldStorage values to variables Chris Angelico <rosuav@gmail.com> - 2011-08-17 10:25 +0100
    Re: CGI: Assign FieldStorage values to variables Gnarlodious <gnarlodious@gmail.com> - 2011-08-17 20:52 -0700
  Re: CGI: Assign FieldStorage values to variables Gnarlodious <gnarlodious@gmail.com> - 2011-08-17 02:20 -0700
  Re: CGI: Assign FieldStorage values to variables Nobody <nobody@nowhere.com> - 2011-08-17 13:45 +0100

csiph-web