gpt4 book ai didi

Python 的 argv 和 bash?

转载 作者:太空宇宙 更新时间:2023-11-04 08:17:21 25 4
gpt4 key购买 nike

我一直在学习和消除对 pythons sys.argv 的一些误解。当我在 bash 中从命令行传递不同的字符时,我注意到:

script.py

import sys
def test(x):
return x

print test(sys.argv)

>>>python script.py [first, second, third]

将打印:

['script.py', '[first,', 'second,', 'third]']

>>>python script.py {first, second, third}

['script.py', '{first,','second,','third}']

但是:

>>>python script.py (first,second,third)

bash: syntax error near unexpected token `('

这是 python 还是 bash,也许两者都是?有什么理由吗?

最佳答案

这是庆典; parens 在子 shell 中运行命令链。

pwd ; ( cd /tmp ; pwd ) ; pwd

如果你想在论证中使用它们,你需要引用它们。

echo '(foo)'

关于Python 的 argv 和 bash?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11999431/

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