# 패키지 & 모듈 # 패키지 == 라이브러리 # 패키지 = 모듈 1 + 모듈 2 = 패키지는 모듈들의 합 # 모듈 == 코드가 들어있는 파일 # 이 코드가 모여서 어떠한 기능을 구현함 # animal package # dog, cat modules # dog, cat modules can sat "hi" from animal import dog # animal 패키지에서 dog 라는 모듈을 갖고와줘 from animal import cat # animal 패키지에서 cat 라는 모듈을 갖고와줘 from animal import * # animal 패키지가 갖고있는 모든 모듈을 다 불러와 # d = dog.Dog() # instance # d.hi() # c = cat.Cat() # c.hi() d = Dog() # instance c = Cat() d.hi() c.hi() print("=======================================") print("=======================================") from geopy.geocoders import Nominatim geolocator = Nominatim(user_agent = "woonie") # location = geolocator.geocode("175 5th Avenue NYC") location = geolocator.geocode("Seoul, South Korea") print(location) print(location.address) print(location.raw)
# animal\__init__.py from .cat import Cat # . <= "이 폴더에 있는" cat.py 이라는 파일에서 Cat 이라는 클래스를 갖고와줘 from .dog import Dog # . <= "이 폴더에 있는" dog.py 이라는 파일에서 Dog 이라는 클래스를 갖고와줘
# animal\cat.py class Cat: def hi(self): print("meow!!") # 고양이가 안녕하는 소리
# animal\dog.py class Dog: def hi(self): print("bark!!") # 개가 안녕하는 소리


'Python > 코딩 1시간만에 배우기_파이썬' 카테고리의 다른 글
12. 핸드폰으로 문자보내기 (0) | 2021.12.29 |
---|---|
10. 상속 (0) | 2021.12.29 |
9. 클래스 (0) | 2021.12.29 |
8. 복습 - 과일 숫자 세는 프로그램 만들기 (0) | 2021.12.29 |
5. 자료구조 - list(리스트) (0) | 2021.12.29 |