How to read/process command line arguments?

I am originally a C programmer. I have seen numerous tricks and “hacks” to read many different arguments.

What are some of the ways Python programmers can do this?

Related

  • What’s the best way to grab/parse command line arguments passed to a Python script?
  • Implementing a “[command] [action] [parameter]” style command-line interfaces?
  • How can I process command line arguments in Python?
  • How do I format positional argument help using Python’s optparse?

18 s
18

import sys

print("\n".join(sys.argv))

sys.argv is a list that contains all the arguments passed to the script on the command line. sys.argv[0] is the script name.

Basically,

import sys
print(sys.argv[1:])

Leave a Comment