วันอาทิตย์ที่ 12 กรกฎาคม พ.ศ. 2552

Edit in place

inputfile.txt

goodbye
hello
see you later!


edit.py

import fileinput
for lines in fileinput.FileInput("inputfile.txt", inplace=1): ## edit file in place
lines = lines.replace("hello","hi")
print lines.replace('\n','') ## although this prints the line, the file will be modified.



inputfile.txt

goodbye
hi
see you later!


จาก ubuntuforums

ไม่มีความคิดเห็น:

แสดงความคิดเห็น