看板 Python 關於我們 聯絡資訊
小的最近寫了一串程式 分別用了很多Print才寫完 但是查到的方法好像都要每次Print就要寫入檔案一次 有沒有什麼辦法是把最後的結果 一次Print出來的指令或方法呢 感謝各位大大及前輩 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 101.8.228.3 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1571386887.A.6ED.html
hank85293: ㄜ先把要print的東西存起來再一次寫檔?10/18 16:58
robert09080: 讀檔 > 存到變數 > 列印10/18 17:42
jiyu520: logger10/18 18:42
papple23g: 開頭寫text="", 然後每次print(my_text)改成text+=my_t10/18 21:09
papple23g: ext+"\n",最後print(text)10/18 21:09
flarehunter: google "python logger to file"10/19 00:46
flarehunter: 或是用cmdline: python aaa.py > out.log10/19 00:48
tacovirus: 用 busm 套件可解,一行 decorator 搞定10/19 10:10
sean50301: logging 可以把output寫到檔案裡面10/19 13:55
sean50301: https://realpython.com/python-logging/10/19 13:56
s860134: 不外乎對 stdin和 stderr 動手腳10/20 17:53
感謝大家,目前是用f大的cmdline取出我要的結果。 但還是想問一下各位大大,logging要用什麼樣的指令才可做到在做後輸出結果呢?還是 一定要 把所有要印出來的東西把print改logging? 感謝 ※ 編輯: qazwsx99876 (101.12.9.40 臺灣), 10/23/2019 18:52:11