加载中...

Python

  1. Home
  2. Computing & Technology
  3. Python

Creating HTML and XHTML Pages in Python - With and Without CGI

By Al Lukaszewski, About.com

4 of 6

Feeding Options To Your Script

If, however, you prefer to feed options to your scripts, this is easily done as well. Using the above example, one simply need to add to the action line the command line argument prefaced with a question mark. If one wants to test for a string argument of '1', the line might look like this:

<form action="./test.cgi?1" method="post">

In the subsequent CGI script 'test.cgi', one would then have an if loop to test whether the argument is '1' or not.

x = sys.argv[1]

if x == '1':
     [do something]
else:
     [do something else]

Explore Python

More from About.com

New Year, New You

Take action today to accomplish your biggest goals with these motivating ideas.

Best Moves in a Bad Economy

Stay on top in this tough economy with our smart, easy-to-follow financial tips.

Python

  1. Home
  2. Computing & Technology
  3. Python
  4. Web Development
  5. Python and HTML - Creating HTML and XHTML Pages in Python - Feeding Options To Your Python Script

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

All rights reserved.