【发布时间】:2018-06-07 08:04:51
【问题描述】:
我正在尝试将表中的数据导出到 txt 文件。我的代码如下
class Optimization_goolge(object):
def __init__(self):
self.dbname = ""
self.usr_name = ""
self.usr_pass = ""
self.con = ""
self.cur = ""
self.openTime=""
def vT(self, x, y, z, openTime):
try:
con_string="dbname = '%s' user = '%s' password ='%s' host = 'localhost'"%(x,y,z)
con = psycopg2.connect(con_string)
con.set_isolation_level(0)
cur = con.cursor()
cur.execute(("""COPY (select source, target, sum(cost)/1000 as cost from distance_matrix where source != 88888888 and target
!= 88888888 group by source, target order by source) TO '%s\\vrp_distance.txt'""") % (os.getcwd()))
con.commit()
但我遇到了错误
error vT Function could not open file "D:\working_copy\vrp_distance.txt" for writing: No such file or directory
Error optimizeFxn_google arguments did not match any overloaded call:
QMessageBox.warning(QWidget, QString, QString, QMessageBox.StandardButtons buttons=QMessageBox.Ok, QMessageBox.StandardButton defaultButton=QMessageBox.NoButton): argument 1 has unexpected type 'Optimization_goolge'
QMessageBox.warning(QWidget, QString, QString, int, int, int button2=0): argument 1 has unexpected type 'Optimization_goolge'
QMessageBox.warning(QWidget, QString, QString, QString, QString button1Text=QString(), QString button2Text=QString(), int defaultButtonNumber=0, int escapeButtonNumber=-1): argument 1 has unexpected type 'Optimization_goolge'
【问题讨论】:
-
因为它来自
getcwd()我猜该目录存在。你有写权限吗?此外,您应该使用os.path.join()加入路径而不是手动方式。您还可以使用.format()来增加可读性。 -
@mikuszefski 是的目录和文件确实存在。如何使用格式()。可以举个例子吗
-
看看下面的答案
标签: python postgresql python-2.7 pyqt4