[英]How to save a file to a specific directory and choose the file's name in python?
[英]How to let choose the directory to save csv file in python?
我具有使用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)
導出是一個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)
這樣的事情將解決問題。 只需將路徑作為參數傳遞即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.