먼저,
travel폴더 생성 후 thailand.py, vietnam.py, __init_.py 파일 생성
# import 뒤에는 모듈이나 패키지만 가능하다.
import travel.thailand
trip_to = travel.thailand.ThailandPackage()
trip_to.detail()
# import로 클래스까지 선언하면 생략가능하다.
from travel.thailand import ThailandPackage
trip_to = ThailandPackage()
trip_to.detail()
from travel import vietnam
trip_to = vietnam.VietnamPackage()
trip_to.detail()
# __all__
# * 쓴다는 것은 travel 모든 패키지를 가져오겠다는 이야기인데 실제로는 개발자가 문법상에서 공개범위를 설정해야 한다.
from travel import *
# trip_to = vietnam.VietnamPackage()
trip_to = thailand.ThailandPackage()
trip_to.detail()
# 패키지,모듈 위치 확인
import inspect
import random
print(inspect.getfile(random)) # inspect.getfile을 통해 모듈 및 패키지의 폴더위치를 알 수 있다.
print(inspect.getfile(thailand))
'Python' 카테고리의 다른 글
Python-내장, 외장 함수 (0) | 2020.07.08 |
---|---|
Python- pip install (0) | 2020.07.08 |
Python-모듈 사용법 (0) | 2020.07.08 |
Python-init (0) | 2020.07.05 |
Python-class (스타크래프트 예시) (0) | 2020.07.05 |