There are a few modules specialized in parsing command line arguments: getopt, optparse and argparse. optparse is deprecated, and getopt is less powerful than argparse, so I advise you to use the latter, it'll be more helpful in the long run.

Here's a short example:

import argparse

# Define the parser
parser = argparse.ArgumentParser(description='Short sample app')

# Declare an argument (`--algo`), saying that the 
# corresponding value should be stored in the `algo` 
# field, and using a default value if the argument 
# isn't given
parser.add_argument('--algo', action="store", dest='algo', default=0)

# Now, parse the command line arguments and store the 
# values in the `args` variable
args = parser.parse_args()

# Individual arguments can be accessed as attributes...
print args.algo

That should get you started. At worst, there's plenty of documentation available on line (say, this one for example)...

Answer from Pierre GM on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ command-line-arguments-in-python
Command Line Arguments in Python - GeeksforGeeks
In Python, command line arguments are values passed to a script when running it from the terminal or command prompt.
Published ย  December 17, 2025
Discussions

Is it possible to pass arguments into a Python script? - Unix & Linux Stack Exchange
I know how to pass arguments into a shell script. These arguments are declared in AWS datapipeline and passed through. This is what a shell script would look like: firstarg=$1 secondarg=$2 How do ... More on unix.stackexchange.com
๐ŸŒ unix.stackexchange.com
October 20, 2015
Passing argument to function from command line
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 program to be processed. I want to do the same in python. More on discuss.python.org
๐ŸŒ discuss.python.org
0
0
June 25, 2025
Argument passing in python script
Hey, Iโ€™m working with the invoke python method in UIPaths I want to pass 3 arg to python fuction 2 string and one python obj how can I do that?? More on forum.uipath.com
๐ŸŒ forum.uipath.com
0
0
September 22, 2023
Pass an argument to a Python script
Use sys.argv https://docs.python.org/3/library/sys.html#sys.argv More on reddit.com
๐ŸŒ r/learnpython
7
1
March 6, 2021
๐ŸŒ
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.

๐ŸŒ
Medium
medium.com โ€บ @evaGachirwa โ€บ running-python-script-with-arguments-in-the-command-line-93dfa5f10eff
Running Python script with Arguments in the command line | by Eva Mwangi | Medium
April 22, 2023 - The Argparse module provides more options as compared to the sys module. These options include: ... import argparse def get_sum_of_nums(num1,num2,num3): return(int(num1)+int(num2)+int(num3)) if __name__ == "__main__": parser = argparse.ArgumentParser( description="Script that adds 3 numbers from CMD" ) parser.add_argument("--num1", required=True, type=int) parser.add_argument("--num2", required=True, type=int) parser.add_argument("--num3", required=True, type=int) args = parser.parse_args() num1 = args.num1 num2 = args.num2 num3 = args.num3 print(get_sum_of_nums(num1, num2, num3))
๐ŸŒ
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โ€ฆ
Find elsewhere
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_command_line_arguments.htm
Python - Command-Line Arguments
C:\Python311>python parser2.py ... displays Hello Guest message. ... We can assign default value to an argument in add_argument() method....
๐ŸŒ
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 - Command line arguments are a powerful tool for making your Python scripts more flexible and reusable. They allow you to pass args to python script different inputs to your script each time you run it, making it more versatile. Weโ€™ve explored three easy ways to handle command line arguments โ€“ using sys.argv, the getopt module, and the argparse module.
๐ŸŒ
UiPath Community
forum.uipath.com โ€บ help โ€บ activities
Argument passing in python script - Activities - UiPath Community Forum
Hey, Iโ€™m working with the invoke python method in UIPaths I want to pass 3 arg to python fuction 2 string and one python obj how can I do that??
Published ย  September 22, 2023
๐ŸŒ
Real Python
realpython.com โ€บ python-command-line-arguments
Python Command-Line Arguments โ€“ Real Python
August 27, 2023 - Python exposes a mechanism to capture and extract your Python command-line arguments. These values can be used to modify the behavior of a program. For example, if your program processes data read from a file, then you can pass the name of the file to your program, rather than hard-coding the value in your source code.
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ argparse.html
argparse โ€” Parser for command-line options, arguments and subcommands
The Python interpreter name followed by sys.argv[0] if a directory or a zipfile was passed as argument. The Python interpreter name followed by -m followed by the module or package name if the -m option was used. This default is almost always desirable because it will make the help messages match the string that was used to invoke the program on the command line.
๐ŸŒ
Quora
quora.com โ€บ How-do-you-pass-command-line-arguments-to-a-Python-script-using-the-subprocess-module
How to pass command line arguments to a Python script using the subprocess module - Quora
Answer: You can very well use the advantage of the builtin module sys and the attribute argv , which has enough capabalities to pass the command line arguments to the module . PFB the example..
๐ŸŒ
Python Forum
python-forum.io โ€บ thread-41893.html
Problems passing arguments containing spaces to bash script and then on to python
April 3, 2024 - I am a definite newbie to python. I've written some pretty basic programs that use shell scripts to pass user supplied arguments to my python programs. The problem I have now is that several of my parameters have spaces (for example an address line ...
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ interpreter.html
2. Using the Python Interpreter โ€” Python 3.14.3 documentation
This can be done by passing -i before the script. All command line options are described in Command line and environment. When known to the interpreter, the script name and additional arguments thereafter are turned into a list of strings and ...
๐ŸŒ
MachineLearningMastery
machinelearningmastery.com โ€บ home โ€บ blog โ€บ command line arguments for your python script
Command Line Arguments for Your Python Script - MachineLearningMastery.com
June 20, 2022 - In this tutorial, youโ€™ve seen how we can use the command line for more efficient control of our Python script. Specifically, you learned: How we can pass in parameters to your Python script using the argparse module
๐ŸŒ
Visual Studio Code
code.visualstudio.com โ€บ docs โ€บ python โ€บ debugging
Python debugging in VS Code
November 3, 2021 - Alternately, you can use a custom ... are needed. If you need to pass arguments to the Python interpreter, you can use the pythonArgs property....
๐ŸŒ
Stanford CS
cs.stanford.edu โ€บ people โ€บ nick โ€บ py โ€บ python-main.html
Python main() - Command Line Arguments
$ python3 affirm.py -affirm Lisa Everything is coming up Lisa $ python3 affirm.py -affirm Bart Looking good Bart $ python3 affirm.py -affirm Maggie Today is the day for Maggie $ Command line arguments, or "args", are extra information typed on the line when a program is run.
๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ accessing-command-line-arguments-python
Accessing command-line arguments in Python - Python Morsels
August 30, 2021 - If we wanted to grab the argument after our program name we could read the second item (index 1) from sys.argv: ... If I pass more than one argument our program is currently just ignoring everything after that first argument: ... $ python3 greet.py Traceback (most recent call last): File "/home/trey/greet.py", line 3, in <module> print("Hello", sys.argv[1]) IndexError: list index out of range