Python Link PG Database

Python uses the psycopg2 package to connect PG data and query the frontal view in the database to obtain the queried data value.

import os,psycopg2 as pg
def conn_pg(dbname,host,port,usr,pw):
conn = pg.connect(database=dbname,user=usr,password=pw,host=host,port=port)
print("connected!!!!!")
cur = conn.cursor()
SQLstr = "SELECT mm,imo,lat,lon from inarea where mm='t'"
cur.execute(SQLstr)
lines = cur.fetchall()
print(lines)
if __name__== "__main__":
conn_pg("BH_TEST", "localhost", 5432, "postgres", "root")