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
ไม่มีความคิดเห็น:
แสดงความคิดเห็น