1
(* .c 또는 * .h)과 같은 디렉토리의 특정 파일에 파일 시작 부분에 몇 줄을 추가해야합니다. 아래 코드를 작성했습니다.파이썬의 특정 파일에만 수정하십시오
f = open('filename')
text = f.read()
f.close()
f = open('filename~', 'w')
f.write("This is the new first line\n")
f.write(text)
f.close()
os.rename('filename~', 'filename')
디렉토리의 모든 파일을 가져 와서 업데이트합니다. 하지만 특정 파일을 업데이트해야합니다. 수행 방법
고맙습니다. 아래 링크에서 abt에게 glob 모듈을 기본적으로 알려줍니다. http://www.doughellmann.com/PyMOTW/glob/ http://www.doughellmann.com/PyMOTW/fnmatch/index.html#module-fnmatch –