1. Technology
Send to a Friend via Email

Programming CGI With Python


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.
  1. About.com
  2. Technology
  3. Python
  4. Web Development
  5. Python CGI - Other Methods of Accessing Data With Python's CGI

©2014 About.com. All rights reserved.