Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import psycopg2
- from lxml import etree
- tree = etree.parse("xmltest/rinf.xml")
- opname = tree.findall(".//OPName")
- opnames =[]
- for op in opname:
- value = op.get("Value")
- opnames.append(value)
- try:
- conn = psycopg2.connect("dbname='rinf' user='postgres' host='localhost' password='12345678' port='5432'")
- except:
- print("Connetion problem!")
- cur = conn.cursor()
- #print(opnames)
- insert_query = "INSERT INTO opp (name) VALUES (%s);"
- try:
- cur.executemany(insert_query, [(name,) for name in opnames])
- except Exception as e:
- print("SQL command cannot be used:", e)
- conn.commit()
- conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement