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!

tentkl
  • 85
  • 8

3 Answers3

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.

chepner
  • 497,756
  • 71
  • 530
  • 681
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://stackoverflow.com/a/3024202/693140

Stefan Kögl
  • 4,383
  • 1
  • 27
  • 34
  • 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 = **argv** – tentkl Oct 18 '17 at 19:45
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.

DevShark
  • 8,558
  • 9
  • 32
  • 56