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 :
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 !
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.