Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import psycopg2.extras
- try:
- conn = psycopg2.connect("user='postgres' host='localhost' password='postgres'",
- )
- except:
- print "I am unable to connect to the database"
- cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
- cur.execute("""SELECT datname from pg_database""")
- rows = cur.fetchall()
- print "nShow me the databases:n"
- print rows
- [['template1'], ['template0'], ['postgres'], ['iip'], ['test'], ['test_postgres'], ['testdb']]
Add Comment
Please, Sign In to add comment