gpt4 book ai didi

python - 配置 SublimeREPL 导入本地模块

转载 作者:太空宇宙 更新时间:2023-11-03 15:37:03 24 4
gpt4 key购买 nike

我希望 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com