강의

멘토링

커뮤니티

Inflearn Community Q&A

chansfj1459's profile image
chansfj1459

asked

Getting Started with Programming: Introduction to Python (Inflearn Original)

File Write(1-2)

readline 질문

Written on

·

336

0

readline을 이용해 한문장씩 출력할 때, 한줄의 공백이 발생하는 이유는 무엇인가요?

그리고

에서 a가 아닌 w를 써도 덮어쓰기가 되지 않고 개행되어 써지는 이유는 무엇인가요?

python

Answer 1

0

niceman님의 프로필 이미지
niceman
Instructor

한줄의 공백은 readline 등을 한 뒤에 line.strip(): 메소드로 공백을 제거해 주시면 됩니다.

코드를 실행해보니 덮어쓰기가 동작하는데 운영체제 권한 부분을 확인해보세요.

또는 뒤에 배울 os 패키지 내용으로 파일이 존재하면 삭제 후 쓰기를 진행하시면 됩니다.

chansfj1459's profile image
chansfj1459

asked

Ask a question