加载中...

Python

  1. Home
  2. Computing & Technology
  3. Python

Reading from a PostgreSQL Database With Python

From Al Lukaszewski, for About.com

9 of 9

Finishing and Executing the Program

Finally, we should return Python's attention from the main() function and finish off the program.

     return

if __name__ == '__main__':
     main()
As usual, the last loop evaluates the runtime command from the user and passes Python's attention to main().

One can now call the program with the necessary four arguments.

python ./readpostgresql.py cornucopia id > 0
The results are tasty:
(1, 'banana')
(2, 'kiwi')
(3, 'nectarine')

Using this knowledge, you can easily automate access to several PostgreSQL databases and collate the data for any purpose. With my tutorial on inserting data, one can even create new databases "automagically".

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. Database Programming
  5. Reading PostgreSQL With Python - Finishing and Executing the PythonProgram

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

All rights reserved.