python列表如何删除第一个和最后一个_Python枚举删除列表的最后一个元素

我正在处理这篇文章

here尝试解析一些命令行参数,但我构建的脚本不断删除最后一个参数.

为了保持简单,我重现了这样的问题:

import getopt

argv = ["-c", "config", "-o", "hello", "-e", "fu bar", "-q", "this is a query"]

opts, args = getopt.getopt(argv, "c:o:e:q", ["cfile=", "ofile=", "entry=", "query="])

for opt, arg in opts:

print(opt, arg)

这是我得到的输出:

-c config

-o hello

-e fu bar

-q

我哪里错了?

冒号(:)不是分隔符,它需要遵循

in the docs所述的每个参数:

shortopts is the string of option letters that the script wants to recognize, with options that require an argument followed by a colon (':'; i.e., the same format that Unix getopt() uses).

因此,您应该将“c:o:e:q”更改为“c:o:e:q:”

您链接的教程也以相同的方式使用它.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值