gpt4 book ai didi

python - 在 emacs 的 comint-mode 中使用参数执行 python 脚本

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

我正在为 python 脚本编写一个 comint 模式。

脚本可以启动:

/usr/bin/python3.3 tool-name arg0

我正在使用 comint-mode,因为此调用会在运行前在提示中询问一些信息。

如果我创建:

(defun create-app ()
"create application by using python tool"
(interactive)
(progn
(setq default-directory "/path/to/tool")
(setq buffer (get-buffer-create "*buffer_name*"))
(apply 'make-comint-in-buffer "tool" buffer "/usr/bin/python3.3" nil nil)
)
)

一切正常,python 已启动,但如果我写:

(defun create-app ()
"create application by using python tool"
(interactive)
(progn
(setq default-directory "/path/to/tool")
(setq buffer (get-buffer-create "*buffer_name*"))
(apply 'make-comint-in-buffer "tool" buffer "/usr/bin/python3.3 tool-name arg0" nil nil)
)
)

缓冲区告诉我它不能执行程序“/usr/bin/python3.3 tool-name arg0”

有没有人知道(有或没有 comint)我如何启动这个 python 进程并让脚本在启动前询问一些信息?

最佳答案

make-comint-in-buffer 的文档字符串(C-hfmake-comint-in-bufferRET) 声明如下

(make-comint-in-buffer NAME BUFFER PROGRAM &optional STARTFILE &restSWITCHES)Make a Comint process NAME in BUFFER, running PROGRAM.If BUFFER is nil, it defaults to NAME surrounded by `*'s.If there is a running process in BUFFER, it is not restarted.PROGRAM should be one of the following:- a string, denoting an executable program to create via  `start-file-process'- a cons pair of the form (HOST . SERVICE), denoting a TCP  connection to be opened via `open-network-stream'- nil, denoting a newly-allocated pty....If PROGRAM is a string, any more args are arguments to PROGRAM.

So the correct way to use the function is to have the only name of the program as a string and pass the arguments to be passed to the program, as additional arguments to make-comint-in-buffer as follows

(apply 'make-comint-in-buffer "tool" buffer "/usr/bin/python3.3" nil "tool-name" "arg0")

关于python - 在 emacs 的 comint-mode 中使用参数执行 python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22561151/

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