Updated:

less than 1 minute read

개요

  • import 방법
    • test 패키지에 func 함수가 있다고 가정
    • 패키지 전체
      • import test
      • 패키지명을 붙여서 사용(test.func())
    • 특정 함수
      • from test import func
      • 패키지명 없이 사용
    • 이름 변경
      • 패키지
        • import test as t
      • 특정 함수
        • from test import func as f


예제

  • 코드
    • test.py
         def func1():
             print("func1 call")
              
              
         def func2():
             print("func2 call")
      
    • main.py
         import test
         import test as t
         from test import func2
         from test import func2 as f2
              
         if __name__ == "__main__":
             test.func1()
             t.func1()
             func2()
             f2()
      
  • 실행 결과
     func1 call
     func1 call
     func2 call
     func2 call