Ejemplo n.º 1
0
    except ValueError:
        print("잘못된 값을 입력하였습니다.")

    except SoldOutError:
        print("재고가 소진되어 더 이상 주문을 받지 않습니다.")
        break                                 # 무한루프 탈출하기


# 모듈
# : 확장자 .py 필요한 것들끼리(함수 정의 클래스 정의) 담은 라이브러리


theater_module.price(3)
theater_module.price_morning(4)
theater_module.price_soldier(5)


mv.price(2)
mv.price_morning(4)
mv.price_soldier(3)

price(4)
price_morning(2)
price_soldier(4)


price(5)
price_morning(6)
# price_soldier(7) import 가 되지 않아 사용할 수 없음
Ejemplo n.º 2
0
def price(people):
    print(f'{people} 명 가격은 {people*10000}입니다.')


def price_morning(people):
    print(f'{people} 명 조조할인 가격은 {people*6000}입니다.')


def price_soldier(people):
    print(f'{people} 명 군인할인 가격은 {people*5000}입니다.')


#모듈 실행
import theater_module

theater_module.price(3)
theater_module.price_morning(4)
theater_module.price_soldier(2)

import theater_module as mv
mv.price(3)
mv.price_morning(4)
mv.price_soldier(2)

from theater_module import *
price(3)
price_morning(4)
price_soldier(2)
Ejemplo n.º 3
0
# urllib
# from urllib import request
# target = request.urlopen("https://www.naver.com")
# output = target.read()

# print(output)


# 극장에서 현금만 받는다. 잔돈을 바꿔주지않는다. 정확히 사람수에 따라 가격이 얼마인지 계산하는 모듈 
# theater_module.py로 만들기 (현 프로젝트 폴더와 같은 경로에 만들기)

import theater_module
theater_module.price(3) # 3명 일반가격 
theater_module.price_morning(4) # 조조할인 가격 
theater_module.price_soldier(5) # 군인할인 가격 
print()

import theater_module as tm 
tm.price(3)
tm.price_morning(4)
tm.price_soldier(5)
print()

from theater_module import *
price(3)
price_morning(4)
price_soldier(5)
print()

from theater_module import price, price_morning # 필요한 함수만 명시 
Ejemplo n.º 4
0
#             waiting +=1
#             chicken -=order
#         if chicken ==0:
#             raise SoldOutError
#     except ValueError:
#         print("잘못된 값을 입력하였습니다.")
#     except SoldOutError:
#         print("재고가 소진되어 더 이상 주문을 받지 않습니다.")
#         break

#모듈 부품끼리, 만들어진 타이어만 교체, 부품만 교체하도록 (유지보수 쉽고 수정 쉽게)
#잔돈을 돌려주지 않는 영화관, 금액에 맞춰서 줘야한다. (가격을 미리 알 수 있는 모듈 만들어보자.)
import theater_module
theater_module.price(3)  #3명이서 영화보러 갔을 때 가격
theater_module.price_morning(4)  #4명이서 조조할인 영화 가격
theater_module.price_soldier(5)  #5명의 군인이 영화보러 갔을 때

import theater_module as mv  #별명 붙이기
mv.price(3)
mv.price_morning(4)
mv.price_soldier(5)

from theater_module import *
#from randeom import*
price(3)
price_morning(4)
price_soldier(5)

from theater_module import price, price_morning  #필요한 것만
price(5)
price_morning(6)
Ejemplo n.º 5
0
# 일정 부분만 교체하고 추가할 수 있도록 만들어 코드의 재사용, 유지 보수를 쉽게 하는 것
# 파이썬 모듈 확장자: .py

# import theater_module
import theater_module as tm

tm.price(3)
tm.price_soldier(4)
tm.price_morning(5)

from theater_module import price, price_morning, price_soldier

price(3)
price_morning(4)
price_soldier(5)

from theater_module import price_soldier as ps

ps(5)
Ejemplo n.º 6
0
'''
모듈
'''
# import theater_module
# theater_module.price(3)
# theater_module.price_morning(3)
# theater_module.price_soldier(3)

import theater_module as mv
mv.price(2)
mv.price_morning(3)
mv.price_soldier(4)

# from theater_module import *
# # from random import *
# price(3)
# price_morning(4)
# price_soldier(5)

# from theater_module import price, price_morning
# price(2)
# price_morning(2)
Ejemplo n.º 7
0
# 방법1
import theater_module  # .py 붙이지 않기
theater_module.price(4)
theater_module.price_morning(3)
theater_module.price_soldier(5)  # theater_module 반복됨

# 방법2
import theater_module as tm  # theater_module 반복을 피하기 위해 tm으로 이름붙임
tm.price(3)
tm.price_morning(2)

# 방법3
from theater_module import *  # from random import *
price(6)
price_soldier(4)

# 방법4
from theater_module import price, price_morning  #theater_module이름의 모듈에서 price와 price_morning을 가져다 쓰겠다.
price(7)

# 방법5
from theater_module import price_soldier as cheap
cheap(5)
'''[import 모듈]
→ 해당 모듈 전체를 가져온다.
  사용하려면 항상 '모듈명.메소드' 와 같이 모듈명을 앞에 붙여주어야 한다.

   [from 모듈 import 메소드 / 변수]
→ 해당 모듈 내에 있는 특정 메소드나 모듈 내 정의된 변수를 가져온다.
  가져온 메소드나 변수를 앞에 모듈명을 붙이지 않고 그대로 사용할 수 있다.
  다만, 이름이 같은 변수나 메소드가 존재할 경우 대체된다.
Ejemplo n.º 8
0
# 11-1. 모듈 (a.k.a. 부품, 확장자 - .py)

# 모듈사용 - import
import theater_module
theater_module.price(3)  # 3명이서 영화 보러 갔을 때 가격
theater_module.price_mornig(4)  # 4명이서 조조 할인 영화 보러 갔을때
theater_module.price_soldier(5)  # 5명의 군인이 영화 보러 갔을때

# as
import theater_module as mv
mv.price(3)
mv.price_mornig(4)
mv.price_soldier

from theater_module import *  # theater_module 모듈 모두 사용
# from random import *
price(3)
price_mornig(4)
price_soldier(5)

from theater_module import price, price_mornig, price_soldier
price(5)
price_mornig(6)
price_soldier(7)  # 오류

from theater_module import price_soldier as price
price(5)  # == price_soldier(5)

# 11-2. 패키지 (모듈들을 모아놓은 집합)

import travel.thailand
Ejemplo n.º 9
0
#방법 1
import theater_module
theater_module.price(3)
theater_module.price_morning(3)
theater_module.price_soldier(3)

#방법 2
import theater_module as tm  #이름이 길 경우에 as를 써서 이름을 줄일 수 있음
tm.price(3)
tm.price_morning(3)
tm.price_soldier(3)

# #방법 3   *은 모듈에 있는 모든 것을 쓰겠다
# from theater_module import *
# price(3)
# price_morning(3)
# price_soldier(3)

#방법 3-1
from theater_module import price,price_morning  #이렇게 원하지 않는 부분은 빼고 사용 가능 여기서도 as써서 함수이름 지정가능 
price(3)
price_morning(3)
# price_soldier(3)
Ejemplo n.º 10
0
import theater_module as mv # theater_module를 mv란 변수명으로 정의
mv.price(3) # 3명 일반가격
mv.price_morning(4) # 4명 조조할인
mv.price_soldier(5) # 5명 군인할인

from theater_module import *
price(3)
price_morning(4)
price_soldier(5)

from theater_module import price, price_morning
price(5)
price_morning(6)
# price_soldier를 import하지 않았기때문에 사용 불가

from theater_module import price_soldier as ps # theater_module의 price_soldier를 ps라 정의
ps(5)