[英]How to let choose the directory to save csv file in python?
I have this function with python that create a simple CSV outFile but i want that i choose the directory of save with windows explorer, my function : 我具有使用python创建一个简单的CSV outFile的功能,但是我希望我选择使用Windows资源管理器保存的目录,我的功能是:
def exporter():
name_of_file="export"
l = [[1, 2], [2, 3], [4, 5]]
completeName = os.path.abspath("C:\temp\%s.csv" % name_of_file)
out = open(completeName,"w")
for row in l:
for column in row:
out.write('%d;' % column)
out.write('\n')
out.close()
QObject.connect(export, SIGNAL('clicked()'),exporter)
export is a QPushButton ,Thanks ! 导出是一个QPushButton,谢谢!
def exporter(directory='C:\temp\\'):
name_of_file = "export"
l = [[1, 2], [2, 3], [4, 5]]
completeName = os.path.abspath("C:/temp/%s.csv" % name_of_file)
full_path = '%(directory)s\%(name_of_file)s.csv' % locals()
out = open(full_path, "w")
for row in l:
for column in row:
out.write('%d;' % column)
out.write('\n')
out.close()
QObject.connect(export, SIGNAL('clicked()'),exporter)
Something like this will do the trick. 这样的事情将解决问题。 Just pass in the path as an argument.
只需将路径作为参数传递即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.