CGI: Assign FieldStorage values to variables

2011-08-17 Thread Gnarlodious
I get a construct like this: form=FieldStorage(None, None, [MiniFieldStorage('name1', 'Val1'), MiniFieldStorage('name2', 'Val2'), MiniFieldStorage('name3', 'Val3')]) Now how would I assign every variable name* its value? lI did try locals().update(form) however I get name2 -

CGI: Assign FieldStorage values to variables

2011-08-17 Thread Gnarlodious
I get a construct like this: form=FieldStorage(None, None, [MiniFieldStorage('name1', 'Val1'), MiniFieldStorage('name2', 'Val2'), MiniFieldStorage('name3', 'Val3')]) Now how would I assign every variable name* its value? lI did try locals().update(form) however I get name2 -

Re: CGI: Assign FieldStorage values to variables

2011-08-17 Thread Gnarlodious
I should add that this does what I want, but something a little more Pythonic? import cgi, os os.environ[QUERY_STRING] = name1=Val1name2=Val2name3=Val3 form=cgi.FieldStorage() form dict = {} for key in form.keys(): dict[ key ] = form[ key ].value dict locals().update(dict) name3 -- Gnarlie --

Re: CGI: Assign FieldStorage values to variables

2011-08-17 Thread Chris Angelico
On Wed, Aug 17, 2011 at 10:06 AM, Gnarlodious gnarlodi...@gmail.com wrote: I get a construct like this: form=FieldStorage(None, None, [MiniFieldStorage('name1', 'Val1'), MiniFieldStorage('name2', 'Val2'), MiniFieldStorage('name3', 'Val3')]) when I need to assign the variable name2 the value

Re: CGI: Assign FieldStorage values to variables

2011-08-17 Thread Chris Angelico
On Wed, Aug 17, 2011 at 10:19 AM, Gnarlodious gnarlodi...@gmail.com wrote: import cgi, os os.environ[QUERY_STRING] = name1=Val1name2=Val2name3=Val3 form=cgi.FieldStorage() form dict = {} for key in form.keys(): dict[ key ] = form[ key ].value You could probably use a list comp for this,

Re: CGI: Assign FieldStorage values to variables

2011-08-17 Thread Gnarlodious
I should add that this does what I want, but something a little more Pythonic? import cgi, os os.environ[QUERY_STRING] = name1=Val1name2=Val2name3=Val3 form=cgi.FieldStorage() form dict = {} for key in form.keys(): dict[ key ] = form[ key ].value dict locals().update(dict) name3 -- Gnarlie --

Re: CGI: Assign FieldStorage values to variables

2011-08-17 Thread Nobody
On Wed, 17 Aug 2011 02:06:31 -0700, Gnarlodious wrote: I get a construct like this: form=FieldStorage(None, None, [MiniFieldStorage('name1', 'Val1'), MiniFieldStorage('name2', 'Val2'), MiniFieldStorage('name3', 'Val3')]) Now how would I assign every variable name* its value? Don't do

Re: CGI: Assign FieldStorage values to variables

2011-08-17 Thread Chris Rebert
On Wed, Aug 17, 2011 at 2:19 AM, Gnarlodious gnarlodi...@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=Val1name2=Val2name3=Val3 form=cgi.FieldStorage() form dict = {} for key in

Re: CGI: Assign FieldStorage values to variables

2011-08-17 Thread Gnarlodious
On Aug 17, 3:25 am, Chris Angelico wrote: You do NOT want end users having the power to set variables. Thanks for the warning, I can see I will need to quarantine the form input. And update() is out of the question. -- Gnarlie http://Gnarlodious.com/ --