作者mymiss312 (mymiss)
看板Python
标题[问题] 如何同时读写一个档案?
时间Fri Sep 12 19:08:37 2014
请问一下我在尝试自动加资料到同一个档案的实作
<?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://webptt.com/cn.aspx?n=bbs/Python/M.1410520120.A.35A.html
1F:→ apua: 没看到 ``oupputfile.close()`` , 这没问题吗? 09/12 21:39