gpt4 book ai didi

python - 从 Applescript 运行 Python 脚本时出错

转载 作者:行者123 更新时间:2023-12-01 05:45:58 24 4
gpt4 key购买 nike

为什么这不起作用?

苹果脚本:

set script_path to "$HOME/Desktop"
do shell script "python & script_path & hello_world.py"

Python 脚本:

#!/usr/bin/env python
print "Content-Type: text/html"
print
print """\
<html>
<head>
<title>Python - Hello World</title>
</head>
<body>
Hello World
</body>
</html>

“”“

错误:

tell current application do shell script "python & script_path & hello_world.py" --> error "sh: script_path: command not found sh: hello_world.py: command not found" number 127 Result: error "sh: script_path: command not found sh: hello_world.py: command not found" number 127

最佳答案

& 符号连接字符串文字和变量替换。就像这样:

set script_path to "$HOME/Desktop"
do shell script "python " & script_path & "/hello_world.py"

您还需要在 hello_world.py 之前或 $HOME/Desktop 末尾添加斜杠。上面的示例将其显示在 hello_world.py 之前。

关于python - 从 Applescript 运行 Python 脚本时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16126058/

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