1. Home
  2. Computing & Technology
  3. Python

Reading from a PostgreSQL Database With Python

By Al Lukaszewski, About.com

4 of 9

Receiving Command Line Arguments for the PostgreSQL Statement - II

With that understanding, we then need to assign values to these variables using the sys module. The sys module has an attribute argv which is an array holding arguments from when the program is executed. By way of example, when one uses the shell command 'mkdir', the name of the directory to be created is the first (and only) argument of the command. If using Python's sys.argv, this argument would be sys.argv[1] -- the name by which the program is executed is always sys.argv[0]. Each additional argument follows in sequence.

Our program will take four arguments, one for each part of the SELECT statement to be made.

table = sys.argv[1]
column = sys.argv[2]
string = sys.argv[3]
operation = sys.argv[4]

4 of 9

Explore Python

More from About.com

  1. Home
  2. Computing & Technology
  3. Python
  4. Database Programming
  5. Reading PostgreSQL With Python - Receiving Command Line Arguments for the PostgreSQL Statement - II

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

All rights reserved.