私は何かに悩まされています。 私はjson文字列を含むファイルを作成して、postgresデータベースにインポートします。しかし、pythonスクリプトによる内部テストではファイルが存在していても、ファイルはインポートされません。スクリプトが完了するまでファイルが書き込まれません
しかし、スクリプトが完了した後でpostgresのインポートを実行すると、問題なくコピーされます。または、別のスクリプトでラップして1つのスクリプトから呼び出すと、動作しますが、両方の要求が同じスクリプト。私はclose()、fsync、flushを試みましたが運がありません。
誰でも助けてもらえますか?
関連コードは以下のとおりです。
command=str("PGPASSWORD=password psql -d database -U postgres -V -c \"copy import.table from Data.txt'\"")
print command
dataFile=open('Data.txt','w')
for x in xx:
xString=json.loads(data)
xString[i]['source']=x
xString[i]['created_at'].replace('"','')
xStringJson=json.dumps(xString)
dataFile.write(xStringJson)
dataFile.close
dataFile.flush()
os.fsync(dataFile)
print os.path.isfile('Data.txt')
pg_command(command)
i=i+1
は 'f.close'は' f.close() ' –