I have a function I'm trying to execute which calls in 4 different variables:
def listdbtables(dbname, user, host, password):
try:
conn = psycopg2.connect("dbname = %s username = %s host = %s pass = %s" % dbname, % user, % host, % password)
curs = conn.cursor()
b = curs.execute("\l")
print b
except psycopg2.DatabaseError, ex:
print "I am unable to connect the database: " + ex
sys.exit(1)
I am unable to read in the variables with my current setup, how do I call in the variables properly in the conn variables.
Edit: Here is the error I am seeing:
File "./pg_meta.py", line 35
conn = psycopg2.connect("dbname = %s username = %s host = %s pass = %s" (% dbname, % user, % host, % password))
^
SyntaxError: invalid syntax