파이썬 파일 내용 추가

hello world가 써있는 텍스트 파일을 읽어서 그 아래에 hello world를 추가하고 싶다.

 

코드는 간단하다. file open함수의 두번째 인자를 추가모드인 a로 둔다.

 

file = open(FILE_SRC, "a") # a option is append
file.write("hello world\n")
file.close()

 

전체코드

https://github.com/HydroponicGlass/2022_Library_Python/blob/main/File/File.py

 

참고

https://docs.python.org/ko/3/library/functions.html?highlight=open#open