![](/img/trans.png)
[英]How to allow users to download an excel file using python/Flask?
[英]How do you allow users to upload 2 excel files in a Python script via terminal, than download a new file file?
我已經使用 pandas 構建了一個數據處理工具。 我的腳本需要 2 個非常大的 excel 文件(超過 17000 行)轉換為 dfs 並匯總和合並 2 個數據幀。 這給我留下了最后一個df。 我的問題是我希望這個腳本被我以外的人使用。 我可以通過使用輸入 function 獲得某些變量的值(使用 Python 3)
例如:
WinRate = input("Enter the Win Rate Percentage:")
但我正在努力尋找一種方法來允許用戶上傳 2 個文件以實際運行腳本。 我希望他們能夠下載后續的 output 文件。 您能給我的任何幫助將不勝感激。 謝謝。
您可以使用 Tkinter 創建一個簡單的 gui。 Tkinter 有一個 function 來顯示一個文件對話框。 然后,您可以向您的用戶詢問 2 個輸入文件(一個接一個)和 output 的文件名。 然后,您可以在腳本中使用這些文件名
import tkinter
import tkinter.filedialog
root = tkinter.Tk()
root.withdraw() # Remove background screen
# Ask for name of inputfiles
excelfile1 = tkinter.filedialog.askopenfilename(parent=root, title="Select first Excel file", defaultextension = ".xlsx")
excelfile2 = tkinter.filedialog.askopenfilename(parent=root, title="Select second Excel file", defaultextension = ".xlsx")
# Ask for name of outputfile
output_excel = tkinter.filedialog.asksaveasfilename(parent=root, title="Give name of outputfile", defaultextension=".xlsx")
# ... Use excel files in the rest of your script
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.