Python tutorial explains it:

import sys

print(sys.argv)

More specifically, if you run python example.py one two three:

>>> import sys
>>> print(sys.argv)
['example.py', 'one', 'two', 'three']
Answer from SilentGhost on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › command-line-arguments-in-python
Command Line Arguments in Python - GeeksforGeeks
import getopt, sys args = sys.argv[1:] ... ... Error handling: catches invalid options. argparse is the easiest and most powerful way to handle command-line arguments in Python....
Published: December 17, 2025
Discussions

Could someone explain command-line arguments in Python?
When you run a python script from the command line, you can pass arguments to the script by adding it after the script name. For example: python my_script.py arg1 arg2 arg3 To utilize these arguments, you can take a look at the sys module (someone else already mentioned it I believe). A quick example would be like this: import sys arg1 = sys.argv[1] arg2 = sys.argv[2] etc... More on reddit.com
🌐 r/learnpython
6
2
November 13, 2017
Modifying Python Script to Accept Command Line Arguments?
https://docs.python.org/3/library/argparse.html More on reddit.com
🌐 r/learnpython
5
2
March 3, 2024
Using command line arguments vs input
Take any simple command-line utility. Let's say dir on Windows (the same applies to anything else though). Most of the time you just want to see the list of files, so you type dir. If you want a wider output you can type dir /w. If you want to display the owner of the file you can do dir /q. There are a pile of other options that you can use on the command line. If you were to write the dir command using something like input() instead, the user experience would be horrible: > dir Do you want a wide listing (Y/N)? N Do you want to display the owner (Y/N)? N Do you want to show read-only files (Y/N)? Y Do you want ot use lower-case? (Y/N)? N ... and another 20-odd questions to answer before you see the list of files More on reddit.com
🌐 r/learnprogramming
5
1
June 8, 2022
Command Line Arguments in Python
so lets assume that we have a program with a filename: 'abc.py', we can run it with the command 'python abc.py'. We can add arguments after this command and parse these arguments in the program, and implement a logic according to these arguments. For example, lets assume that our command is 'python abc.py 1'. We must import the sys module, and with sys.argv[0] we can get the 0. index which is the '1' argument in our command. We can now do anything we want with this data. More on reddit.com
🌐 r/learnprogramming
4
2
July 28, 2021
🌐
Python.org
discuss.python.org › python help
Passing argument to function from command line - Python Help - Discussions on Python.org
June 25, 2025 - My son wrote a command line program in ruby for me. I want to convert it to python. To run the program he has done this on the command line; “./myProgram.rb ‘argument’”. Then the 'argument ’ is passed into the progra…
🌐
Codecademy
codecademy.com › article › command-line-arguments-in-python
Command Line Arguments in Python (sys.argv, argparse) | Codecademy
Python provides three main ways to handle command-line arguments: sys.argv: A simple way to access command-line arguments as a list of strings. getopt: A built-in module for parsing command-line options and arguments in a structured way.
🌐
Jon Macey's WebPages
nccastaff.bournemouth.ac.uk › jmacey › SEForMedia › seminars › Arguments › Arguments
Command Line Arguments | Jon Macey's WebPages
September 19, 2024 - The simplest way to access command line arguments in Python is to use the sys.argv variable. This variable is a list of strings that contains the command line arguments passed to the program.
🌐
Hyperskill
hyperskill.org › university › python › command-line-arguments-in-python
Command Line Arguments in Python — sys.argv & argparse Guide
August 10, 2026 - These inputs are handy for tailoring the programs actions adjusting results or providing data. In Python one can. Interpret command line arguments by employing the sys module or more sophisticated modules such, as argparse and getopt.
Find elsewhere
🌐
Medium
moez-62905.medium.com › the-ultimate-guide-to-command-line-arguments-in-python-scripts-61c49c90e0b3
The Ultimate Guide to Command Line Arguments in Python Scripts | by Moez Ali | Medium
April 18, 2023 - Compared to other types of user ... the need for user interaction. In Python, command-line arguments are accessed through the sys.argv list....
🌐
Stanford CS
cs.stanford.edu › people › nick › py › python-main.html
Python main() - Command Line Arguments
We choose the more sensible name "args" to hold the command line args, and we use a slice to skip over the unhelpful string at index 0, thus creating an args list that is exactly just the command line arguments.
🌐
Python
docs.python.org › 3 › library › argparse.html
argparse — Parser for command-line options, arguments and subcommands
Arguments read from a file must be one per line by default (but see also convert_arg_line_to_args()) and are treated as if they were in the same place as the original file referencing argument on the command line.
🌐
Codecademy
codecademy.com › docs › python › command line arguments
Python | Command Line Arguments | Codecademy
September 26, 2025 - This example demonstrates how to access and use Python command line arguments using the sys module: ... Hello, Alice! ... The sys.argv list contains the script name as the first element, followed by all arguments passed from the command line. All arguments are stored as strings, so type conversion is needed for numeric operations. The getopt module provides a more structured approach to parsing command line options, similar to the C getopt() function.
🌐
Medium
medium.com › towardsdev › python-how-to-read-command-line-arguments-d4f3221ac29d
Python: How to read command line arguments | by Konstantinos Patronas | Towards Dev
October 9, 2024 - In Python, you can read the first command-line argument passed to a script using the sys.argv list from the sys module. The first element…
🌐
Tutorialspoint
tutorialspoint.com › python › python_command_line_arguments.htm
Python - Command-Line Arguments
Python's standard library includes a couple of useful modules to parse command line arguments and options − · getopt − C-style parser for command line options.
🌐
Analytics Vidhya
analyticsvidhya.com › home › 3 easy ways to handle command line arguments in python
3 Easy Ways to Handle Command Line Arguments in Python
January 15, 2025 - The simplest way to handle command line arguments is by using the sys module’s argv. The argv is a list in Python, which contains the command-line-arguments pass argument to python script. The first argument, argv[0], is always the script name itself. ... The getopt module is a more powerful tool for parsing command line arguments.
🌐
Educative
educative.io › answers › command-line-arguments-in-python
Command-line​ arguments in Python
The sys.argv contains the list of command-line arguments. len(sys.argv) is the number of total command-line arguments. In the code below, press the run button and then try running this script: ... # necessary library to ensure command is read in terminal. import sys #sys.argv contains arguments which are input in the terminal. print ('Number of arguments:',len(sys.argv)) # Arguments are printed as a list print ('Arguments:', str(sys.argv)) print(sys.argv[0]) #will print main.py
🌐
iO Flood
ioflood.com › blog › python-command-line-arguments
Python Command Line Arguments: Complete Guide
February 7, 2024 - At the heart of using command line arguments in Python is the sys.argv list. This built-in Python list automatically captures all command-line inputs in your script. The sys.argv list works in a straightforward way. It’s indexed from zero, and each command line argument is a string in this list.
🌐
Scaler
scaler.com › home › topics › command line arguments in python
Command Line Arguments in Python - Scaler Topics
January 16, 2024 - Modules like sys.argv, argparse, and getopt aid in parsing and managing command line arguments. Python's command-line support allows interaction with scripts through various input parameters, offering flexibility in execution and interaction with the command line interface. Choose from our industry-leading programs designed for career success
🌐
Reddit
reddit.com › r/learnpython › modifying python script to accept command line arguments?
r/learnpython on Reddit: Modifying Python Script to Accept Command Line Arguments?
March 3, 2024 -

I am trying to modify an already existing code (https://github.com/ohyicong/decrypt-chrome-passwords/blob/main/decrypt_chrome_password.py) to take in command line arguments an example: python script.py "path_to_Local_State_file" "path_to_Login_Data_file" I think that this should be a pretty simple fix but chatGPT is not giving me the correct code when I test it how should I approach this.

🌐
CloudxLab
cloudxlab.com › home › how to handle command line arguments in python? | cloudxlab blog
How to handle Command Line Arguments in Python? | CloudxLab Blog
June 28, 2021 - When you are running python programs from the command line, you can pass various arguments to the program and your program can handle it. Here is a quick snippet of code that I will be explaining later: import sys if __name__ == "__main__": print("You passed: ", sys.argv) When you run this program from the command line, you will get this kind of results:
🌐
AskPython
askpython.com › python › python-command-line-arguments
Python Command Line Arguments - 3 Ways to Read/Parse - AskPython
September 11, 2019 - If your script requires simple command-line arguments, you can go with sys.argv. But, if your program accepts a lot of positional arguments, default argument values, help messages, etc, then you should use argparse module. The getopt module works too but it’s confusing and hard to understand. ... I have been working on Python programming for more than 12 years.