如何从另一个脚本访问Python变量访问?

时间:2016-10-21 18:45:37

标签: database postgresql python-2.7 python-3.x connection

实施例。 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的连接字符串。

0 个答案:

没有答案