2
作爲主題,這是代碼,沒有錯誤消息,但數據沒有得到插入。 這是我的代碼,誰能告訴我它有什麼問題?使用Postgres和Python不能「複製」
import psycopg2
import sys
import os
import glob
import csv
#open the csv folder
dictfile='******'
os.chdir(dictfile)
total=[]
for file in glob.glob("*.csv"):
total.append(file)
con = None
try:
con = psycopg2.connect(host='localhost',database='*****',user='postgres', password='*****')
cur = con.cursor()
for i in range(0,1):
filename='/Users/Shared'+'/'+total[0]
print filename
#better move all files into shared folder
x="copy public.crossref_sample from "+ "'"+filename+"'"+" DELIMITERS ',' CSV"
print x
cur.execute(x)
except psycopg2.DatabaseError, e:
print 'Error %s' % e
sys.exit(1)
finally:
if con:
con.close()
我在代碼中看不到提交 –
謝謝,它現在可以運行 – user1652287