在Python中使用命令行参数:了解sys.argv [英] Using command line arguments in Python: Understanding sys.argv

查看:122
本文介绍了在Python中使用命令行参数:了解sys.argv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习困难的方式学习Python".我认为该示例可能已过时,因此我想在此获得反馈.

I'm currently going through Learn Python The Hard Way. I think this example might be out dated so I wanted to get feedback here on it.

我正在使用Python 3.1

I'm using Python 3.1

from sys import argv

script, first, second, third = argv

print("the script is called:", (script))
print("your first variable is:", (first))
print("your second variable is:", (second))
print("your third variable is:", (third))

我收到此错误:

Traceback (most recent call last):
  File "/path/ch13.py", line 3, in <module>
    script, first, second, third, bacon = argv
ValueError: need more than 1 value to unpack

你知道怎么了吗?

推荐答案

您忘记了将参数传递给脚本,例如foo.py bar baz quux.

You forgot to pass arguments to the script, e.g. foo.py bar baz quux.

这篇关于在Python中使用命令行参数:了解sys.argv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆