实施例。 Script1.py
import psycopg2
def func1(dname, username, hostname, password):
try:
conn = psycopg2.connect(database=dname, user=username, password=password, host=hostname)
print "Connection Successful"
cur = conn.cursor()
return cur
except:
print "I am unable to connect to the database"
Script2.py
from script1 import func1
cur = func1('XXXX', 'localhost', 'password', 'sample_db',)
cur.execute("select * from test")
# it is working fine till this line
我需要访问从script1到script2的连接字符串。