[Python] 파일 다루기 (JSON, CSV)
1. 파일 읽기 open() 함수를 이용해 파일을 불러와 변수에 저장한다. read() 메서드를 이용해 파일을 읽을 수 있는 형태로 변환한다. close() 메서드를 이용해 사용하지 않는 파일을 닫아 메모리를 절약한다. # 파일 열기/닫기 file = open('data.txt') content = file.read() file.close() with open() as file: 구문을 활용해 indent 범위가 끝나면 파일이 자동적으로 닫히게 한다. # 파일 자동으로 닫기 with open('data.txt') as file: content =file.read() 줄 단위로 읽기 with open('data.txt') as file: for line in file: print(line) 두번째 인자에 ..