问题描述
诸如此类的便捷
(python-command-to-string &rest COMMANDS)
,然后返回Python解释器的输出。
例如
(python-command-to-string
"import jedi"
"print(
jedi.Script(
code=\"[].append(0)\"
).infer(line=1,column=4)[0].full_name
)")
将返回"builtins.list.append"
。
使用临时.py文件可以完成工作,但是我很想拥有一种可重用的通用方法。
解决方法
丑陋但有点用。 ?
(defun python-command-to-string (&rest COMMANDS)
"Use shell to call python."
(shell-command-to-string
(concat "python -c \"" (string-join COMMANDS "\n") "\"")))
(python-command-to-string
"import numpy as np"
"print(np.arange(6))"
"print('blah blah')"
"print('{}'.format(3))"
)
现在在python代码中使用双引号存在问题。我猜想在调用此函数时,“仅单引号”约束没有任何危害。只是不要用${}
之类的东西来破坏外壳。