실습
파이썬3 및 Atom 에디터를 설치하지 않았다면 <파이썬3 설치 하기> 영상을 보고 설치해주시기 바랍니다.
모든 실습은 자신의 PC 환경에서 진행하는걸 권장하며 Atom 에디터가 아닌 다른 텍스트 에디터를 사용해도 무관합니다. (ex: Sublime Text, Pycharm 등)
실습
파이썬3 및 Atom 에디터를 설치하지 않았다면 <파이썬3 설치 하기> 영상을 보고 설치해주시기 바랍니다.
모든 실습은 자신의 PC 환경에서 진행하는걸 권장하며 Atom 에디터가 아닌 다른 텍스트 에디터를 사용해도 무관합니다. (ex: Sublime Text, Pycharm 등)
최종 코드
반드시 영상을 보시고 직접 실행해보시고, 아래 제시된 최종 코드는 참고만 하시기 바랍니다.
han = open('mbox-short.txt')
for line in han:
line = line.rstrip()
wds = line.split()
if len(wds) < 3 or wds[0] != 'From' :
continue
print(wds[2])
comment
han=open("mbox-short.txt")
을 하면
FileNotFoundError: [Errno 2] No such file or directory: 'mbox-short.txt'
분명 같은 폴더에 넣었는데도 이렇게 나오는건 제가 무엇을 잘 못 했을까요?
7강에서도 마찬가지였어요.
답답하네요.
han=open("mbox-short.txt")
for line in han:
line=line.rstrip()
wds=line.split()
if len(wds)<3 or wds[0]!='From':
continue
print(wds[2])
#가디언을 먼저 써야하는 이유 : 만약 리스트가 비어있는경우 wds[0]에 접근하려고하면 인덱스 오류가 발생한다. 따라서 먼저 리스트의 개수가 3개보다 적은지를 확인하게되면 그 조건이 참일때 뒤 조건을 확인하지않게되면서 오류가 발생하지않는다.
mbox = open("mbox-short.txt")
for line in mbox:
if not line.startswith("From"):
continue
line.rstrip()
mail_list = line.split()
print(mail_list[1])
len(wds)<3이 없으면 wds[2]와 충돌 에러가 발생하네요 ㅎ
son = open("mbox-short.txt")
for line in son:
line = line. rstrip()
main = line. split()
if main[0] != "From" :
continue
print(main[2])
han = open('mbox-short.txt')
for line in han:
line = line.rstrip()
wds = line.split()
if len(wds) < 3 or wds[0] != 'From' :
continue
print(wds[2])
오! 번역!
han = open("mbox-short.txt")
for line in han :
line = line.rstrip()
if len(line.split()) < 1 :
print("Skip Blank!")
continue
else :
if len(line.split()) > 2 :
wds = line.split()
if wds[0] != 'From' :
continue
print(wds[2])
이렇게 짜봤는데 역시 제가 봐도 날림으로 만든거 같네요
어렵네요 설명이
fhandle = open("mbox-short.txt")
for line in fhandle:
if line.startswith("From"):
first = line.split()
if len(first) > 3:
print(first[2])
비공개 글입니다.
wds[0]! ='From':
! 가 뭐죠? 조건문에 !가 있는게 ..?
tf = open("mbox-short.txt")
for line in tf:
if line.startswith("From"):
a = line.split()
try:
print(a[2])
except:
continue
han = open('mbox-short.txt')
for line in han:
line = line.rstrip()
wds = line.split()
# guardian in a compound statement
if len(wds) < 3 or wds[0] != 'From' :
continue
print(wds[2])
han = open('mbox-short.txt')
for line in han:
line = line.rstrip()
wds = line.split()
# guardian in a compound statement
if len(wds) < 3 or wds[0] != 'From':
continue
print(wds[2])
하아....8강 진심 무슨 말인지 1도 모르겠어여 ㅠㅠ...6주 다되가는데 갈수록 이해만 안되서 속터지기만하네여 ㅠㅠ
진짜 초급 맞는거...죠?
디버깅하는 방법
11:40
0807
갑자기 유튜브로 바꼈네요
중간중간에 번역이 정확하지 않거나 번역이 아예 안 된 부분이 있거나 자막이 안 맞는 부분도 있는 것 같습니다. 시정해주시면 좋겠습니다.