[學習計畫] [簡易控制] Python 基本運算與繪圖_2
(4)Python 存檔案(.txt) 程式中使用之範例: with open("basic_python_basic_1.txt", "w") as text_file: save_inf = "set_amplitude: "+str(set_amplitude) + ", set_frequency: "+str(set_frequency) print(save_inf, file=text_file) with open("basic_python_basic_1.txt", "w") as text_file: 開啟檔案,其中"w"為寫入指令(檔案存在時則清空後取代)。 print(save_inf, file=text_file): 將資料存進剛才定義的檔案中。 參考資料 [1] Print string to text file https://stackoverflow.com/questions/5214578/print-string-to-text-file 輸出結果: Github 連結: Basic Python 1