→ eamansf96xs: 我現在的方法是for line 然後list.append(int(line))08/20 19:49
→ eamansf96xs: 但感覺不太好 因為硬要轉int 感覺降低效能08/20 19:49
→ s860134: 一次 read ,replace 就好了阿08/20 20:14
→ s860134: with open 是讓你少寫一行 f.close()08/20 20:15
→ eamansf96xs: 要怎麼一次replace ...08/20 20:53
→ eamansf96xs: 可以寫個大概嗎?08/20 20:55
→ papple23g: 可以用split()08/20 20:56
→ eamansf96xs: fread讀進來 是存在哪種資料結構 我看不出來08/20 2
0:59
→ eamansf96xs: 如果知道的話應該很好處理08/20 21:00
※ 編輯: eamansf96xs (117.19.160.95 臺灣), 08/20/2019 21:00:35
推 robert09080: 讀完資料有\n,可以使用str.split()08/20 22:59
→ robert09080: 檔案應該是txt所以讀進來會是str還是要轉才會變int吧08/20 23:04
→ eamansf96xs: 好的 感謝08/20 23:26
→ eamansf96xs: r大的方法 正是我要的!! 覺得python太多種寫法很08/20 23:28
→ eamansf96xs: 方便 但是以前寫c 有些語法真的很難接受08/20 23:28
→ eamansf96xs: with open就是其中一個08/20 23:28
推 TitanEric: with 是context manager 確保在進入function前後需要08/21 10:10
→ TitanEric: 做的行為 像with open就會幫你關檔08/21 10:10
※ 編輯: eamansf96xs (117.19.160.95 臺灣), 08/21/2019 10:41:19