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 my tutorial on programming CGI with Python. 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.
- This is NOT the Beginning
- Python Best Practice: the Bang Line
- The Tasks This Python Program Must Do
- Holding the User Data in Python With CGI
- Holding the User Data in Python With PHP
- Defining the First Python Function
- Reading the RSS Feed as a Python File Object
- Using a Python Iterator
- Calling Python's Function, Retrieving the Feed Address
