加载中...

Python

  1. Home
  2. Computing & Technology
  3. Python

Programming CGI With Python

By Al Lukaszewski, About.com

4 of 4

Other Methods of Accessing Data

In addition to 'getvalue', the following methods may be used to access form data by field name:

  • form.getfirst Returns the first value found for a field by the given name
  • form.getlist Returns a list of all values found for a field by the given name. If no values are found, it returns an empty list.

In a case where each field name is unique, all three methods will return the same results. So the following will return the same data:

name = form.getvalue('name')
name = form.getfirst('name')
name = form.getlist('name')
The method 'getlist', however, will return a list of values. The others will simply return a string.

4 of 4

Index: Programming CGI With Python

  1. Python CGI First Steps: Importing cgi and cgitb
  2. Accessing CGI Form Data
  3. Attributes of FieldStorage
  4. Other Methods of Accessing Data

Explore Python

More from About.com

Python

  1. Home
  2. Computing & Technology
  3. Python
  4. Web Development
  5. Python CGI - Other Methods of Accessing Data With Python's CGI

©2009 About.com, a part of The New York Times Company.

All rights reserved.