CGI FieldStorage instances?

Tim Roberts timr at
Mon Nov 22 05:25:52 CET 2010

Gnarlodious <gnarlodious at> wrote:
>I'm having a hard time understanding this, can someone explain?
>Running a CGI with query string:
>Script includes these lines:
>Form Contents:
>action: <class 'cgi.MiniFieldStorage'>
>MiniFieldStorage('action', 'Find')
>page: <class 'cgi.MiniFieldStorage'>
>MiniFieldStorage('page', 'Data')
>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:

    print form['action'].value
    print form['page'].value

If you're not sure whether the value will be specified:

    if 'action' in form:
        action = form['action'].value
Tim Roberts, timr at
Providenza & Boekelheide, Inc.

More information about the Python-list mailing list