我希望SublimeREPL能够自动加载本地模块,这样我就可以从REPL中调用模块中的函数而无需先导入它们。例如,util_func.py
包含以下内容:
import datetime
fdate = lambda: datetime.date.today().strftime('%Y-%m-%d')
所以我可以在打开一个新的REPL之后立即打字:
>>> fdate()
'2017-02-24'
这可能吗?提前谢谢。
答案 0 :(得分:1)
事实证明这很简单。我刚刚将以下内容添加到Packages/User/SublimeREPL/config/Python/Main.sublime-menu
。选择此添加定义的菜单选项将执行util_func.py
并进入REPL。
[
{
"id": "tools",
"children":
[{
"caption": "SublimeREPL",
"mnemonic": "R",
"id": "SublimeREPL",
"children":
[
{"caption": "Python",
"id": "Python",
"children":[
{"command": "repl_open",
"caption": "Python",
"id": "repl_python",
"mnemonic": "P",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python", "-i", "-u", "PATH TO utility_func.py"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
}
]}
]
}]
}
]
请务必使用正确的路径替换上面的PATH TO utility_func.py
。