파이썬 패키지
하지만 다음과 같이 echo_test 함수를 사용하는 것은 불가능하다.
>>> import game
>>> game.sound.echo.echo_test()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'sound'
import game을 수행하면 game 디렉터리의 모듈 또는 game 디렉터리의 __init__.py에 정의한 것만 참조할 수 있다.
라고 점프 투 파이썬 5-3 패키지 내용에서 말합니다
import game을 할 때 game폴더에 있는 모듈을 참조할 수 있다고하는데
예를들어 game폴더에 __init__ 과 test.py 이 있을 때에
import game만을 써서 test를 어떻게 참조할 수가 있을까요?
tntsale147 님 476
M 2020년 11월 23일 4:43 오후
1개의 답변이 있습니다. 1 / 1 Page
안녕하세요.
game 디렉터리 하위에 __init__.py 와 mytest.py 파일이 다음과 같이 있을 경우
___init__.py
from . import mytest
mytest.py
def abc():
print("abc")
다음과 같이 사용할 수 있습니다.
>>> import game
>>> game.mytest.abc()
abc
박응용 님
M 2020년 11월 23일 6:51 오후