Advertisement
Guest User

Untitled

a guest
Feb 14th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. import psycopg2
  2.  
  3. import psycopg2
  4.  
  5. try:
  6. conn = psycopg2.connect("dbname='template1' user='dbuser' host='localhost'
  7. password='dbpass'")
  8. except:
  9. print "I am unable to connect to the database"
  10.  
  11. cur = conn.cursor()
  12. cur.execute("""SELECT datname from pg_database""")
  13. rows = cur.fetchall()
  14.  
  15. print "nShow me the databases:n"
  16. for row in rows:
  17. print " ", row[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement