import simpleset을 실행하면 simpleset.pyc 파일이 생성 됨
pyc 파일이 생성된 다음 import 구문을 실행하면 별도의 인터프리팅 없이 어트리뷰트를 현재의 이름공간으로 가져오거나 모듈의 이름을 현재 이름공간으로 가져 옴
testmodule.py 생성 후 저장
# -*- coding: cp949 -*-
print("test module")
defaultvalue = 1
def printDefaultValue():
print(defaultvalue)
>>> import testmodule
test module
>>> testmodule.printDefaultValue()
1
testmodule.py의 코드를 수정
# -*- coding: cp949 -*-
print("hello world")
defaultvalue = 2
def printDefaultValue():
print(defaultvalue)
다시 임포트
>>> import testmodule <<임포트 했지만 hello world라는 문장이 출력되지 않음
>>> testmodule.printDefaultValue()
1 << 여전히 기본값 1이 찍힘
한번 로딩한 모듈은 다시 임포트해도 수정된 부분이 반영되지 않음
프로그램을 종료하거나 파이썬 인터프리터를 종료한 다음 다시 임포트해야 함
>>> import imp
>>> imp.reload(testmodule) << testmodule을 리로드함
hello world << 리로드를 하면 모듈의 코드가 다시 수행됨
<module 'testmodule' from '/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/testmodule.py'>