gpt4 book ai didi

python - Scala:带参数的python脚本的系统命令

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

所以我在 Scala 中发送这个系统命令:

val command = "python other/evaluateAnswers.py 'chemistry earth' 'the chemistry of the world in champaign' 'the chemistry of the computer science world'"

命令.!!

这是我的 python 代码的简化版本:

def main(argv):
# example run:
print(argv)
# do stuff here ...

if __name__ == '__main__':
main(sys.argv[1:])

如果我直接在终端内运行:

daniel$ python other/evaluateAnswers.py 'chemistry earth' 'the chemistry of the world in champaign' 'the chemistry of the computer science world'

这是我的 python 代码中 print(argv) 的结果:

['chemistry earth', 'the chemistry of the world in champaign', 'the chemistry of the computer science world']

这是正确的。

如果我通过 command.!! 从 scala 运行它,我会在 print(argv) 的输出中得到以下内容:

["'chemistry", "earth'", "'the", 'chemistry', 'of', 'the', 'world', 'in', "champaign'", "'the", 'chemistry', 'of', 'the', 'computer', 'science', "world'"]

这是不正确的拆分。

有什么地方出错了吗?

最佳答案

手动拆分我的 scala 命令就成功了:

val command = Seq("python", "other/evaluateAnswers.py", "'chemistry earth'", "'the chemistry of the world in champaign'", "'the chemistry of the computer science world'")
command.!!

关于python - Scala:带参数的python脚本的系统命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41575841/

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