강의주소 : https://youtu.be/kWiCuklohdY
1. 모듈의 사용
(1) 모듈 및 사용
(1) 불러오기
(2) 축약하여 불러오기
import theater_module as mv #축약어 설정
mv.price(3)
mv.price_morning(3)
mv.price_soldier(3)
(3) 모두 불러오기
from theater_module import *
#from random impor*
price(3)
price_morning(3)
price_soldier(4)
(4) 필요한 함수만 불러오기
from theater_module import price, price_morning #필요한 함수만 불러오기
price(4)
price_morning(4)
(5) 필요한 함수 1개에 축약어 설정하여 불러오기
from theater_module import price_soldier as price
price(10)
2. 패키지 / 모듈의 묶음
(1) 일반
(2)
from travel.thailand import ThailandPackage
trip_to = ThailandPackage()
trip_to.detail()
from travel import vietnam
trip_to = vietnam.VietnamPackage()
trip_to.detail()
3. 패키지에서 ALL 것을 가져올 수 있는 방법
from travel import *
# trip_to = vietnam.VietnamPackage()
trip_to = thailand.ThailandPackage()
trip_to.detail()
4. 모듈 내부 / 외부에서 실행 확인
(1) 내부
class ThailandPackage:
def detail(self):
print("[태국여행] 방콕, 파타야 여행(야시장 투어) 50만원")
if __name__ == "__main__":
print("thailand 모듈을 직접실행")
print("이 문장은 모듈을 직섭실행할 때 실행됨")
trip_to = ThailandPackage()
trip_to.detail()
else:
print("thailnad 외부에서 모듈을 호출중")
(2) 외부
from travel import *
# trip_to = vietnam.VietnamPackage()
trip_to = thailand.ThailandPackage()
trip_to.detail()
5. 모듈의 파일경로
from travel import *
# # trip_to = vietnam.VietnamPackage()
# trip_to = thailand.ThailandPackage()
# trip_to.detail()
import inspect
import random
print(inspect.getfile(random))
print(inspect.getfile(thailand))
** 모듈 이동 후 경로 확인
from travel import *
# # trip_to = vietnam.VietnamPackage()
trip_to = thailand.ThailandPackage()
trip_to.detail()
import inspect
import random
print(inspect.getfile(random))
print(inspect.getfile(thailand))
6. 패키지 생성하기, 기존에 개발되어있는 패키지 모음 사이트
(1) 설치한 패키지 리스트 확인
(2) 설치한 패키지 정보 확인
7. 내장함수
#input : 사용자 입력을 받는 함수
language = input("좋아하는 언어?")
print("{0}는 좋은 언어" .format(language))
# dir : 어떤 객체를 넘겨줬을 대 그 객체가 어떤 변수와 함수를 가지고 있는지 표시해줌
print(dir())
import random #외장함수
print(dir())
import pickle
print(dir())
# dir : 어떤 객체를 넘겨줬을 대 그 객체가 어떤 변수와 함수를 가지고 있는지 표시해줌
# print(dir())
import random #외장함수
# print(dir())
# import pickle
# print(dir())
print(dir(random))
lst = [1,2,3]
print(dir(lst))
name = "jim"
print(dir(name))
8. 외장함수
# glob : 경로내의 폴더 /파일목록 조회 (윈도우 dir)
import glob
print(glob.glob("*.py")) #확장가 py인 모든 파일
# os : 운영체제에서 제공하는 기본 기능
import os
print(os.getcwd()) #현재 경로를 표시
다시 실행하면
-- 코드 수정
import os
print(os.getcwd()) #현재 경로를 표시
folder = "sample_dir"
if os.path.exists(folder) :
print("이미 존재함")
os.rmdir(folder)
print(folder, "폴더를 삭제함")
else:
os.makedirs(folder) #폴더 생성
print(folder, "폴더생성함")
import time
print(time.localtime())
print(time.strftime("%Y-%m-%d %H:%M:%S"))
import datetime
print("오늘", datetime.date.today())
# timedelta 두 날짜사이의 간격
today = datetime.date.today() #오늘날짜 저장
td = datetime.timedelta(days=100) # 100일 저장
print("태어난지 100일은", today+td) # 오늘부터 100일 후
퀴즈
---------------------- 내가 만든거
------------------ 기초강의 완료 ----- 한달걸림 21.07.19~21.08.19 한달걸림.
0 댓글