SublimeREPL에서 타사 모듈 가져오기
-
23-12-2019 - |
문제
그래서 SublimeREPL 사용법을 배우고 있는데 문제가 발생했습니다.
나는 main.py
파일과 같은 폴더에 timer.py
.나는 쓴다 import
의 진술 main.py
:
import timer
그럼 내가 열면
1) SublimeREPL --> Python --> Python--IPython을 실행하고 코드를 InteractiveConsole로 전송하면 오류가 발생합니다.
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "<string>", line 1, in <module>
ImportError: No module named timer
2) SublimeREPL --> Python --> Python을 실행하고 코드를 REPL 콘솔로 전송하면 예상대로 실행됩니다.
이유가 무엇인지 궁금합니다.
해결책
이는 sys.path에 지정된 디렉터리가 포함되어 있지 않기 때문입니다.아래 코드를 통해 편집할 수 있습니다.
import os
import sys
sys.path.append(os.getcwd())
# os.getcwd() is the current directory, make sure it's the right one.
이렇게 하면 타이머.py를 가져올 수 있습니다.
제휴하지 않습니다 StackOverflow