- 8
- 이니스프리
- 조회 수 866
안녕하세요?
굉장히 기초적인 질문이지만 부끄러움을 무릅쓰고 질문드려요~
파이썬에서 출력문의 종류에는 화면 출력, 파일 출력 등이 있겠죠.
그런데 출력문의 결과는 동일할 것이라고 생각을 하는데요.
Beautifulsoup의 결과를 print 문으로 출력하는 것과 파일로 출력하는 것과 결과가 왜 다른지 잘 이해가 되지 않네요 ㅠㅠ
스포어를 예로 들어 질문을 드릴게요~
1 2 3 4 5 6 7 8 9 | import requests from bs4 import BeautifulSoup soup = BeautifulSoup(html, 'html.parser' ) print (soup) # 1번 with open ( 'sfu.txt' , 'w' , encoding = 'utf-8' ) as f: # 2번 f.write( str (soup)) |
위 스크립트를 이용하여 화면으로 출력하면 다음과 같이 HTML 소스가 중간에 짤려서 보입니다.
하지만 파일로 출력하면 정상적으로 끝까지(총 1587 라인) 나오더군요 ㅠㅠ
이러한 차이가 왜 발생하는 것인지, 제가 설정을 잘못한 것인지 여쭤봅니다~
그럼 즐거운 성탄절 오후 되세요!
항상 감사드립니다 ^-^
작성자
댓글 8




앗 여태껏 그런 생각을 못했네요 ㄷㄷ
그런데 방금 테스트해보니 아무 키나 누르면 CMD 창이 닫혀버리는데요~ ㅠㅠ



음.. 혹시 소스코드가 저장된 파일을 더블클릭해서 실행하고 계신가요??
만약 그러면 CMD에서 해당 경로로 간 다음에 python [저장된 파일 이름] 과 같이 해서 전부 나오는지 확인해보시겠어요??


앗 저는 VS Code에서 F5를 누르면 CMD에서 돌아가도록 설정했는데요.
말씀해주신대로 shift + R click으로 해당 경로를 CMD에서 열고 python 파일명.py 이렇게 실행하니깐 끝까지 출력되네요~ ㄷㄷ
감사합니다!!
혹시 어떤 이유 때문에 이렇게 중간에 짤리는 문제가 발생하는지 알 수 있을까요??
너무 기초적인 질문인 것 같은데 죄송하네요 ㅠㅠ



VS code의 문제인지 아니면 Python 플러그인의 버그인지는 모르겠지만 한줄에 일정 길이 이상의 문자열을 출력할 수 없게 되어 있는 거 같습니다.
s = 'A' * 0x4000 + 'B' * 10
print(s)
이렇게 하고 ctrl+F5 를 하면 뒤쪽의 B는 출력이 되질 않네요..
일단은 해당 파일을 여신 다음에 코드 부분에서 오른쪽 마우스를 클릭한 다음 'Run Python File in Terminal' 을 클릭해서 실행하는 방법으로 사용하시면 될 것 같습니다.


앗 그런 이유가 있군요!! 감사합니다 ^^
'Run Python File in Terminal'이 이럴 때 사용하라고 있는 것이군요~ ㄷㄷ
그럼 humit 님께서도 즐거운 성탄절 되세요!




앗 그렇군요~ 알려주셔서 감사합니다 :)
humit 님께서도 2020년 경자년 새해 복 많이 받으세요~
남은 학업 잘 마무리하시고, 취업도 화이팅이요 ^-^

혹시 저 화면에서 아무 키나 눌렀을 때 다음에 나타나야 할 문장들이 출력되진 않나요??