- from-import를 이용해서 urllib패키지 안 request 모듈에서 urlopen 함수를 불러오는 코드를 작성해봅시다.
- 다음 주소를 urlopen하고, read() 한 다음, 이를 utf-8으로 decode 한 결과를 변수 webpage에 넣어봅시다.https://en.wikipedia.org/wiki/Lorem_ipsum
- 변수 webpage를 출력해봅시다. 무엇이 나오나요?
정답코드
from urllib.request import urlopen
webpage = urlopen("https://en.wikipedia.org/wiki/Lorem_ipsum").read().decode(utf-8)
print(webpage)
내가 쓴 오답코드
from urllib import request
from request import urlopen
webpage = decode(read(urlopen("https://en.wikipedia.org/wiki/Lorem_ipsum")),utf-8)
print(webpage)
** 배운 점
- 패키지와 모듈은 온점(.)으로 연결하고 함수를 불러올 때 import 뒤에 위치시키기
- 함수를 연속해서 사용할 때는 온점(.) 이용해 순차적으로 이어서 사용함
'콤퓨타 공부 > Python' 카테고리의 다른 글
[python 공부] 배열의 데이터 타입 dtype (0) | 2021.08.22 |
---|---|
[python 공부] numpy와 list (0) | 2021.08.22 |
[python 공부] import vs. from-import (0) | 2021.08.22 |
[python 공부] 패키지 (0) | 2021.08.22 |
[python 공부] 웹 서버-클라이언트 구조와 라이브러리 (0) | 2021.08.21 |