1. Home
  2. Computing & Technology
  3. Python

Part 1: Laying the Groundwork with HTML, CGI, and PHP

By Al Lukaszewski, About.com

9 of 10

You are Only as Good as Your Data File

Now let's take a look at the data file. For our purposes, a simple, delimited file will suit. Any symbol that does not appear in a web address will suffice -- a tab, a semi-colon, a greater-than sign, etc. While a tab would make this more readable, it could pose a small problem for our implementation until we program a way for the computer to edit the data file. With a tab comes whitespace, and it is very easy for human editors to add extra whitespace and thus throw off the pattern matching we will tell Python to do. For now, it is better to use a semi-colon as a delimiter. So put this data into a text file:

Python;http://z.about.com/6/g/python/b/index.xml Google;http://z.about.com/6/g/google/b/index.xml Home Recording;http://z.about.com/6/g/homerecording/b/index.xml PHP;http://z.about.com/6/g/php/b/index.xml Plus-Size;http://z.about.com/6/g/plussize/b/index.xml Terrorism;http://z.about.com/6/g/terrorism/b/index.xml Weather;http://z.about.com/6/g/weather/b/index.xml WebDesign;http://z.about.com/6/g/webdesign/b/index.xml WebSearch;http://z.about.com/6/g/websearch/b/index.xml Guardian;http://www.guardian.co.uk/rssfeed/0,15065,12,00.xml Spiegel;http://www.spiegel.de/schlagzeilen/rss/0,5291,676,00.xml

You will notice that the order of the datafile is different from the menu listing . Python does not care. In the Python program, the list will be read into a dictionary anyways (for those coming late: a dictionary is an associative array the order of which is randomized; one accesses it by key and not by order).

9 of 10

Explore Python

More from About.com

  1. Home
  2. Computing & Technology
  3. Python

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

All rights reserved.