我希望SublimeREPL自动加载本地模块,以便我可以从REPL调用模块中的函数,而无需先导入它们。例如,util_func.py
包含以下内容:
import datetime
fdate = lambda: datetime.date.today().strftime('%Y-%m-%d')
因此,我可以在打开新的REPL之后立即键入:
>>> fdate()
'2017-02-24'
这可能吗?提前致谢。
最佳答案
原来这很简单。我只是将以下内容添加到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
。关于python - 配置SublimeREPL导入本地模块,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42453610/