What is the exact term for 'argv' in python?
Asked Answered
T

3

5

I am currently trying to grasp the exact name of argv function (if it can be called a function) that can be imported from sys or system-specific parameters. I found 3 definitions:

So which one is it? Perhaps it doesn't matter how one calls it? Does it even have an accepted name?

Thanks everyone!

Takakotakakura answered 18/10, 2017 at 12:41 Comment(5)
arg ... vatever? sorry. this isn't Python specific, but "imported" from C conventionsJonniejonny
According to The C programming Language by Kernighan & Ritchie, argv stands for "argument vector".Metallize
@PM2Ring the world would be a better place if K&R actually invented the vector for C :)Jonniejonny
@Jean-FrançoisFabre haha - this is the best: argv(atever) !!! THANK YOU!Takakotakakura
@Takakotakakura plausible with german accent :)Jonniejonny
P
4

It doesn't really matter. It's a list (not a function), and the name argv is just borrowed from the conventional name used in C. Most of the time, you are better off using a library like argparse to process the command line arguments, in which case you won't even be using sys.argv directly.

Psyche answered 18/10, 2017 at 12:45 Comment(0)
V
2

argv is a variable (a list of arguments), and is therefore not a function.

The naming seems to come from conventions used in C, which uses argc (argument count) and argv (argument vector). See also https://mcmap.net/q/63521/-what-does-int-argc-char-argv-mean

Vernettaverneuil answered 18/10, 2017 at 12:46 Comment(1)
Maybe you can explain to me why variable & its arguments are inverted in argv? Normally in python, a variable is created by naming it and assigning arguments: variable = "its argument" or variable = 1 or variable = True; When using argv: argument_1, argument_2 = argvTakakotakakura
A
1

None of these 3 are satisfying, because 1) this is a list and 2) "argument" is vague and misleading (these are actually "command line arguments")

A better term is "list of command line arguments".

From the documentation:

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: this is a bit pedantic, and people will generally understand what you're talking about when they see sys.argv, regardless of what term you chose to call it.

Allamerican answered 18/10, 2017 at 12:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.