CGI FieldStorage instances?
timr at probo.com
Mon Nov 22 05:25:52 CET 2010
Gnarlodious <gnarlodious at gmail.com> wrote:
>I'm having a hard time understanding this, can someone explain?
>Running a CGI with query string:
>Script includes these lines:
>action: <class 'cgi.MiniFieldStorage'>
>page: <class 'cgi.MiniFieldStorage'>
>It looks like every variable in the query string instantiates a
>MiniFieldStorage with that value, is that the case?
Yes, unless it's a "file" type, then it is a full FieldStorage.
>And if so, what
>sort of cool tricks could I do with that feature? Because so far I am
>doing CGI and it is a big old mess. Intercepting every variable is
>complicated and confusing. Is there an easier way?
Have you looked at the source code? That's the beauty of Python. It's all
exposed for you. MiniFieldStorage has a .name attribute and a .value
attribute. So, for example:
If you're not sure whether the value will be specified:
if 'action' in form:
action = form['action'].value
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list