所以我在学习使用SublimeREPL,遇到了一个问题。
我有一个 main.py 文件,在同一文件夹中有一个 timer.py。我在 main.py 中写了 import 语句:
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.
这将使导入 timer.py 成为可能
