ValueError: not enough values to unpack (expected 4, got 1)

前端 未结 4 1585
甜味超标
甜味超标 2020-12-31 13:28
from sys import argv

script, first, second, third = argv
print(\"The script is called: \", script)
print(\"The first variable is: \", first)
print(\"The second vari         


        
相关标签:
4条回答
  • 2020-12-31 13:35

    You could run it like this: python script.py first, second, third

    0 讨论(0)
  • 2020-12-31 13:38

    Run it from the shell like this:

    python script.py arg1 arg2 arg3
    
    0 讨论(0)
  • 2020-12-31 13:49

    argv variable contains command line arguments. In your code you expected 4 arguments, but got only 1 (first argument always script name). You could configure arguments in pycharm. Go to Run -> Edit Configurations. Then create a new python configuration. And there you could specify Script parameters field. Or you could run your script from command line as mentioned by dnit13.

    0 讨论(0)
  • 2020-12-31 13:54

    I think you are running the following command:

    python script.py
    

    You are writing a program which is aksing for 4 inputs and you are giving onle one. That's why you are receiving an error. You can use the below command:

    python script.py Hello How Are
    
    0 讨论(0)
提交回复
热议问题