看板 Python 關於我們 聯絡資訊
請問一下我在嘗試自動加資料到同一個檔案的實作 <?php $arr = array( array("A","B"), array("B","C"),) ?> array 大約有500多行 我想要讀取到空白行的時候塞值進去 最後的目的是要自動加資料到同一個檔案 不過我試著分開寫 也是得到同樣的結果(會有缺漏) 想請問有沒有什麼解決方法呢?? 以下是我的程式碼: searchline = '\n' inputfile = open('a.php','r') lines = inputfile.readlines() # f being the file handle i = lines.index(searchline) # Make sure searchline is actually in the file lines.insert(i+1, 'Different random text') outputfile = open('b.php','w') for line in lines: outputfile.write(line) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.134.156 ※ 文章網址: http://www.ptt.cc/bbs/Python/M.1410520120.A.35A.html
apua: 沒看到 ``oupputfile.close()`` , 這沒問題嗎? 09/12 21:39