1. Home
  2. Computing & Technology
  3. Python

Part 2: Getting Feed Information From the Data File With Python

From Al Lukaszewski, for About.com

4 of 9

Holding the User Data in Python With CGI

In addition to receiving the user data, we need to define a variable to hold the data. Let's call it something obscure like 'feedname'. The way we assign data to feedname depends on whether we are using PHP or CGI as the intermediary.

If we use CGI, we will need to import the cgi and cgitb libraries, enable cgitb, and then assign the data from cgi.FieldStorage to a dictionary from which we will cull the feedname by its HTML name value, 'selection'. The code looks like this:

## CGI Version
import cgi
import cgitb; cgitb.enable()
form = cgi.FieldStorage()
feedname = form["selection"].value

If you are at all uncomfortable with the cgi library, I encourage you to read [link url=/od/cgiformswithpython/ss/pycgitut1.htm] my tutorial on programming CGI with Python. [/link] If CGI is used for this program, the application should have a 'cgi' suffix instead of the usual 'py'. On the next page, we will look at the PHP version of this setup and see how we can code the program to allow command-line execution and debugging.

Explore Python
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Python

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

All rights reserved.