这段python2的argv代码为什么在python3就报错,错误是not enough values to unpack,应该在修改呢?

发布网友

我来回答

3个回答

热心网友

执行的时候参数个数正确才行,我这里程序文件名为test.py。

G:\>test.py 1 2 3 4 5Traceback (most recent call last):  File "G:\test.py", line 4, in <mole>    script, first, second, third = argvValueError: too many values to unpack (expected 4)G:\>test.py 1 2 3The script is called: G:\test.pyYour first variable is: 1Your second variable is: 2Your third variable is: 3G:\>test.pyTraceback (most recent call last):  File "G:\test.py", line 4, in <mole>    script, first, second, third = argvValueError: not enough values to unpack (expected 4, got 1)

热心网友

执行的时候参数个数正确才行,我这里程序文件名为test.py。

G:\>test.py 1 2 3 4 5
Traceback (most recent call last):
  File "G:\test.py", line 4, in <mole>
    script, first, second, third = argv
ValueError: too many values to unpack (expected 4)
G:\>test.py 1 2 3
The script is called: G:\test.py
Your first variable is: 1
Your second variable is: 2
Your third variable is: 3
G:\>test.py
Traceback (most recent call last):
  File "G:\test.py", line 4, in <mole>
    script, first, second, third = argv
ValueError: not enough values to unpack (expected 4, got 1)

热心网友

此题出自《“笨办法”学python》吧,我看的是第三版,实际上在“应该看到的结果”栏目中,习题13会话第一行 $python ex13.py first 2nd 3rd这句就是在cmd里输入的,你可以清楚看到输入的参数。

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com