gpt4 book ai didi

python - sys.argv 没有采用 python 3 中提供的参数

转载 作者:行者123 更新时间:2023-11-28 21:26:20 25 4
gpt4 key购买 nike

我在 Windows 8 中使用 python 3.3.0。

这是我要处理的代码:-

import sys

for arg in sys.argv:
if arg == "-u":
url = sys.argv[2]
print (url)
sys.exit(1)

所以,当我在 cmd 中运行我的程序时:

python my.py -u http://www.aytelecom.ae/news-details.php?id=5&type=2

我只得到 'http://www.aytelecom.ae/news-details.php?id=5' 作为我的 sys.argv[2] 或在 url 变量中!

那么,有人能告诉我为什么要跳过 '&type=2' 吗?我是不是哪里做错了或者 python 3 出了什么问题?

最佳答案

& 是 shell 中的元字符。将网址放在引号中。

关于python - sys.argv 没有采用 python 3 中提供的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13049562/

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