from my_package import calculator print(calculator.plus(10, 5)) print(calculator.minus(10, 5)) print(calculator.multiply(10, 5)) print(calculator.divide(10, 5)) # 방법2. # import 패키지명.모듈명 import my_package.calculator print(my_package.calculator.plus(10,5)) print(my_package.calculator.minus(10,5)) print(my_package.calculator.multiply(10,5)) print(my_package.calculator.divide(10,5)) # 방법3. # import 패키지명.모듈명 as 별칭명 import my_package.calculator as cal print(cal.plus(10,5)) print(cal.minus(10,5)) print(cal.multiply(10,5)) print(cal.divide(10,5)) # 외부 모듈파일 불러오기 import numpy as np import pandas as pd # 1차원 배열 a = np.array([1,2,3,4,5]) print(a) # 1차원 배열 : 한가지 자료형으로 처리 b = np.array([1, 2.0, 3, 4, 5]) print(b) # [1. 2. 3. 4. 5.]
#from 패키지 import 모듈 from my_package import calculator print(calculator.plus(10, 5)) print(calculator.minus(10, 5)) print(calculator.multiply(10, 5)) print(calculator.divide(10, 5))
from my_package.calculator import plus from my_package.calculator import multiply from my_package.calculator import minus from my_package.calculator import divide print(plus(5, 1)) # 함수의 이름만으로 호출 가능 print(multiply(1, 2)) print(minus(1, 2)) print(divide(2, 4))
from my_package import calculator as c print(c.plus(10, 5)) print(c.minus(10, 5)) print(c.multiply(10, 5)) print(c.divide(10, 5))
from my_package import calculator as calc print(calc.plus(10, 5))
from my_package import calculator print(calculator.plus(10, 5)) print(calculator.minus(10, 5)) print(calculator.multiply(10, 5)) print(calculator.divide(10, 5))
# my_package 패키지 안에 있는 calculator.py 모듈 파일 불러오기 # 방법 1. # from 패키지명 import 모듈명 from my_package import calculator print(calculator.plus(10, 3)) # 방법 2 # import 패키지명.모듈명 import my_package.calculator print(my_package.calculator.plus(10, 3)) # print(calculator.plus(10, 3)) # 방법 2로 할 시에는 패키지경로까지 모두 적어주어야 함. # 방법 3 # import 패키지명.모듈명 as 별칭 import my_package.calculator as cal print(cal.plus(10, 3)) print(cal.minus(10, 3)) print(cal.multiply(10, 3)) print(cal.divide(10, 3)) # 예제 import matplotlib.pyplot as plt plt.plot([1, 2, 3, 5]) plt.ylabel('some numbers') plt.show()
#from my_package.calculator import plus #from my_package.calculator import minus from my_package.calculator import plus, minus # 따로 정의 하지 않고 ','를 이용하여 한번에 등록할 수 도 있다. #from my_package.calculator import multiply #from my_package.calculator import divide print(plus(10, 5)) print(minus(10, 5)) #print(multiply(10,5)) #print(divide(10,5)) # my_package.calculator 모듈의 multiply() 함수를 import하지 않아 현재 모듈에서 보이지 않는 함수
from my_package import calculator print(calculator.plus(2, 5))