1. Home
  2. Computing & Technology
  3. Python

Reading from a PostgreSQL Database With Python

From , former About.com Guide

2 of 9

Psycopg and Python: Perfect Together

The module we will use for this tutorial is again psycopg. It is available from http://www.initd.org/projects/psycopg1. So download it and install it using the directions that come with the package.

Once it is installed, you can import it like any other module:

# libs for database interface
import psycopg

If you would like your program to take input from the keyboard, you will also want to import the sys module. In this tutorial, I will illustrate how every major part of the SQL statement can be input from the keyboard. So, let your import line read as follows:

import sys, psycopg

Explore Python
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Python
  4. Database Programming
  5. Reading PostgreSQL With Python - Psycopg and Python: Perfect Together

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

All rights reserved.