Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.061 X-Spam-Evidence: '*H*': 0.88; '*S*': 0.00; 'cpython': 0.05; 'dict': 0.09; 'am,': 0.12; 'subject:values': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.16; 'wed,': 0.17; 'cheers,': 0.18; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'aug': 0.24; 'skip:" 30': 0.28; 'import': 0.28; 'message- id:@mail.gmail.com': 0.29; 'cc:addr:python.org': 0.30; 'url:library': 0.31; 'chris': 0.32; 'does': 0.32; 'fail': 0.34; '17,': 0.34; 'function.': 0.34; 'url:python': 0.36; 'but': 0.37; 'something': 0.37; 'received:google.com': 0.38; 'url:org': 0.38; 'received:209.85': 0.38; 'should': 0.38; 'skip:o 20': 0.38; 'subject:: ': 0.39; 'url:docs': 0.39; 'more': 0.60; 'want,': 0.71; 'sender:addr:chris': 0.84; 'url:functions': 0.84; 'received:209.85.218.46': 0.91; 'received:mail- yi0-f46.google.com': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=YMU0tjlabwQwrzb1vWUuaz4u6GSythtB+ju/N0+oGpg=; b=dBR1SN1Jaw3kFDtosESHV0DRBJlRX3yQkxiW3uoZ4HhRvVdr56T4as+PtWrmf6Nbzh DscHE5PoLMZYsoCRBe2DkXIoqEZh4Togf0EfOOVlgPAJZElme8CDQAqBeuuLjsDupyGq sqI9lr9ORlm02UENCLxdEhgMAp594TU+BxDoc= MIME-Version: 1.0 Sender: chris@rebertia.com In-Reply-To: References: <92d066ff-d0ee-432f-b512-1f2fa01ba681@a12g2000yqi.googlegroups.com> Date: Wed, 17 Aug 2011 09:23:01 -0700 X-Google-Sender-Auth: _wKpa0K0HZFhWipDA3q2SAv1zf0 Subject: Re: CGI: Assign FieldStorage values to variables From: Chris Rebert To: Gnarlodious Content-Type: text/plain; charset=UTF-8 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1313598183 news.xs4all.nl 23922 [2001:888:2000:d::a6]:58220 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11691 On Wed, Aug 17, 2011 at 2:19 AM, Gnarlodious 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