>  기사  >  백엔드 개발  >  특정 줄을 삭제하는 Python 파일 작업에 대한 자세한 설명

특정 줄을 삭제하는 Python 파일 작업에 대한 자세한 설명

高洛峰
高洛峰원래의
2017-03-08 10:02:151986검색

이 쓰기 루프를 건너뛰려면 계속 사용하세요

#文本内容
Yesterday when I was young
昨日当我年少轻狂
The tasting of life was sweet
生命的滋味是甜的
As rain upon my tongue
tasting
I lived by night and shunned the naked light of day
tasting123
And only now I see how the time ran away
tasting
 
tasting

텍스트에서 Tasting123 삭제

with open("fileread.txt","r",encoding="utf-8") as f:
    lines = f.readlines()
    #print(lines)
with open("fileread.txt","w",encoding="utf-8") as f_w:
    for line in lines:
        if "tasting123" in line:
            continue
        f_w.write(line)

파이썬 파일 작업에 대한 자세한 설명과 특정 줄 삭제에 대한 관련 기사를 보려면 다음을 따르세요. PHP 중국어 웹사이트!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.