로딩
요청 처리 중입니다...

[파이썬 기초] - 파일 객체 입출력 메소드

 [파이썬 기초] - 파일 객체 입출력 메소드

이번에는 파일 객체 메소드인 write( ), read( ), readline( ), readlines( )등을 사용하여 파일 객체에 대한 입출력을 해 보자. write( ) 메소드 생성된 파일 객체가 f일 때, f.write(string)는 string의 내용을 파일에 출력하고, 출력한 바이트 수를 반환한다. 텍스트 파일에서 출력할 string은 str( ) 객체이다.

바이너리 파일에서 출력할 string은 bytes, bytearray, memoryview, array.array 등의 바이트 객체가 된다. >>> f1 = open('data.txt', 'w') >>> f1 <_io.TextIOWrapper name='data.txt' mode='w' encoding='UTF-8'> >>> f1.write('lee 80 90 95\n') 16 >>> f1.write('kim 85 70 75\n') 16 >>> f1.write('park 70 80 90\n') 16 >>> f1.cl...

# EOF # 파일객체 # 파이썬 # write # with # readlines # readline # read # Python # open # 파일의끝