import

Jinhyeon Son·2020년 3월 30일
0

정리

목록 보기
7/17

import

다른 모듈에 있는 코드들에 대한 접근권을 얻는 행위

import는 두가지 연산을 수행한다

  • 이름이 가리키는 모듈을 검색 후 로드
  • 검색의 결과를 지역 스코프의 네임 스페이스에 정의

기본

	import test_import

위와 같이 import된 모듈은 test_import.함수명 과 같이 접근한다

from

	from test_import import test_func1
   	from test_import2 import *  	# test_import2 모듈의 모든 객체를 import

위와 같이 import된 모듈은 test_func1로 바로 접근할 수 있지만
local scope의 다른 객체들과 이름 충돌이 날 가능성이 있고
그 충돌의 발생을 알아차리기 쉽지 않아 추천하지 않는 방법이다

import as

	import test_import as my_module
	from test_import2 import test_func1 as my_func2

위와 같이 import된 모듈은 my_module.test_func1, my_func2로 접근 할 수 있다

0개의 댓글