Simplify database (psycopg2) usage by creating a module
Let me preface this by saying that I am fairly new to Python and I apologize if this is not the appropriate place for this question. I am using the psycopg2 module to manipulate a PostgreSQL database. The general usage would look something like this: # Example 1 import psycopg2 conn = psycopg2.connect(database="mydb", user="postgres") cur = conn.cursor() cur.execute ("SELECT * FROM mytable;") rows = cur.fetchall() for i, row in enumerate(rows): print "Row", i, "value = ", row cur.close() conn.close() This will open a connection to the mydb database, select all fields from the table mytable and