Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何关闭当前函数中另一个函数中定义的数据库连接_Python 3.x_Postgresql 9.3 - Fatal编程技术网

Python 3.x 如何关闭当前函数中另一个函数中定义的数据库连接

Python 3.x 如何关闭当前函数中另一个函数中定义的数据库连接,python-3.x,postgresql-9.3,Python 3.x,Postgresql 9.3,''' def数据库_连接(): 尝试: #PostgreSQL连接 Postgres_connection=psycopg2.connect(user=“Postgres”,password=“password”,host=“127.0.0.1”, port=“5432”,database=“Maps”) Postgres\u cursor=Postgres\u connection.cursor() 除了(异常,psycopg2.Error)作为错误1: 打印(“连接到PostgreSQL时

''' def数据库_连接(): 尝试: #PostgreSQL连接 Postgres_connection=psycopg2.connect(user=“Postgres”,password=“password”,host=“127.0.0.1”, port=“5432”,database=“Maps”) Postgres\u cursor=Postgres\u connection.cursor() 除了(异常,psycopg2.Error)作为错误1: 打印(“连接到PostgreSQL时出错”,错误1) 返回Postgres\u连接,Postgres\u光标

def Database_connection_close():
    Postgres_connection=Database_connection()
    Postgres_connection.close()

“”“

def Database_connection():try:#PostgreSQL connection Postgres_connection=psycopg2.connect(user=“Postgres”,password=“password”,host=“127.0.0.1”,port=“5432”,Database=“Maps”)Postgres_cursor=Postgres_connection.cursor(),除了(例外,psycopg2.Error)as error1:print(“连接到PostgreSQL时出错”,error1)返回Postgres_连接,Postgres_cursorabove是我在另一个函数中尝试关闭连接的连接函数,出现错误。请更具体一些我在数据库_连接()中定义了Postgres数据库连接函数我想在database_connection_close()函数中关闭该数据库连接,但当我尝试使用上面提到的代码时,出现了错误。