[169] 파일에서 특정 문자열 교체하기

책 내용에 대한 무단배포 방지를 위해 최소한으로 정리

t1 = input('찾을 단어를 입려하세요: ')
t2 = input('변경할 단어를 입력하세요: ')

with open('mydata.txt', 'r') as f:
	with open('mydata2.txt', 'w') as h:
		text = f.read()
		text = text.replace(t1,t2)
		h.write(text)
	
print(f'{t1}{t2}로 변경했습니다.')

Comments