edit 7
set gateway 118.151.209.177
set priority 1
set device "port3"
set comment "Yashtel"
edit 56
set dst 130.127.205.17 255.255.255.255
set distance 5
set device "Austin-Backup"
set comment " www.scdhhs.gov"
edit 59
set dst 10.100.100.0 255.255.252.0
set distance 5
set device "CityMD"
set comment "Metronet"
텍스트 파일에 위 데이터가 있습니다. 설정 한 장치가 "Austin-Backup"인 경우에만 편집 XX에서 데이터를 추출하여 주석을 설정하려고합니다.텍스트 파일 내용 추출
edit 56
set dst 130.127.205.17 255.255.255.255
set distance 5
set device "Austin-Backup"
set comment " www.scdhhs.gov"
아래는 내 코드입니다 :이 파일은 같은
출력이어야한다 편집 명령의 100 년대가 있습니다. 스트링 = "설정 디바이스"의 oldfile 라인
word = '"Austin-Backup"'
import shutil
aa = open("result.txt", 'a')
with open('test.txt') as oldfile, open('cript.txt', 'r+') as new:
는 :
new.write(line)
new.write('\n')
if string not in line:
pass
elif string in line:
if word in line:
shutil.copy('cript.txt','result.txt')
elif word not in line:
print line
new.seek(0)
new.truncate()
만 라인의 Result.txt 아래 cript.txt가 갖는 코드를 실행 한 후 비어있다.
설정 코멘트 "Metronet"
는 "그것은 작동하지 않습니다"유효한 문제 설명이 아니다. * 무엇이 작동하지 않습니까? 귀하의 질문을 편집하여 오류 또는 추적 목록의 ** 전체 텍스트 **를 포함하여 문제의 [mcve]를 게시하십시오. – MattDMo
한 가지는 글에 들여 쓰기가 잘못되었습니다. 'for' 루프는'with' 문 안에 들어가려면 한 레벨 들여 쓰기해야합니다. – Charles