python 中 'argv' 的确切术语是什么?
What is the exact term for 'argv' in python?
我目前正在尝试掌握可以从 sys[=28 导入的 argv 函数(如果它可以称为函数)的确切名称=] 或 系统特定参数 。我找到了 3 个定义:
- argument vector
- argument value
- argument variable
所以是哪一个?也许人们怎么称呼它并不重要?它甚至有公认的名称吗?
谢谢大家!
没关系。它是一个 list(不是函数),名称 argv
只是从 C 中使用的常规名称借来的。大多数时候,最好使用库像 argparse
来处理命令行参数,在这种情况下你甚至不会直接使用 sys.argv
。
argv
是一个变量(参数列表),因此不是函数。
命名似乎来自 C 中使用的约定,它使用 argc
(参数计数)和 argv
(参数向量)。另见
这 3 个中的 None 令人满意,因为 1) 这是一个列表 2) "argument" 含糊且具有误导性(这些实际上是 "command line arguments")
更好的术语是"list of command line arguments"。
来自文档:
sys.argv
The list of command line arguments passed to a Python script.
argv[0] is the script name (it is operating system dependent whether
this is a full pathname or not). If the command was executed using the
-c command line option to the interpreter, argv[0] is set to the string '-c'. If no script name was passed to the Python interpreter,
argv[0] is the empty string.
To loop over the standard input, or the list of files given on the
command line, see the fileinput module.
PS:这个有点迂腐,一般人看到sys.argv
就会明白你在说什么,不管你叫什么名字[=12] =]
我目前正在尝试掌握可以从 sys[=28 导入的 argv 函数(如果它可以称为函数)的确切名称=] 或 系统特定参数 。我找到了 3 个定义:
- argument vector
- argument value
- argument variable
所以是哪一个?也许人们怎么称呼它并不重要?它甚至有公认的名称吗?
谢谢大家!
没关系。它是一个 list(不是函数),名称 argv
只是从 C 中使用的常规名称借来的。大多数时候,最好使用库像 argparse
来处理命令行参数,在这种情况下你甚至不会直接使用 sys.argv
。
argv
是一个变量(参数列表),因此不是函数。
命名似乎来自 C 中使用的约定,它使用 argc
(参数计数)和 argv
(参数向量)。另见
None 令人满意,因为 1) 这是一个列表 2) "argument" 含糊且具有误导性(这些实际上是 "command line arguments")
更好的术语是"list of command line arguments"。
来自文档:
sys.argv
The list of command line arguments passed to a Python script. argv[0] is the script name (it is operating system dependent whether this is a full pathname or not). If the command was executed using the -c command line option to the interpreter, argv[0] is set to the string '-c'. If no script name was passed to the Python interpreter, argv[0] is the empty string.
To loop over the standard input, or the list of files given on the command line, see the fileinput module.
PS:这个有点迂腐,一般人看到sys.argv
就会明白你在说什么,不管你叫什么名字[=12] =]