First (and probably most preferable) solution is to put the second and third argument in quotes as Susmit Agrawal suggested. Then the shell itself will split the command line into arguments appropriately.

python mytest.py [email protected]  "value of file 1"  "value of file 2"

In case you really need to pass arguments without quotes though, you will have to accept that the shell will be splitting your second and third argument at spaces, so you will need to reconstruct them from sys.argv yourself.

Lastly, you may want to explore argparse library to help you with parsing the command line arguments. In this case you may want to use optional arguments with nargs set to '+' or some certain number based on your command line API. For example, if you define and parse your arguments the following way,

parser = argparse.ArgumentParser()
parser.add_argument('--value-1', nargs=4)
parser.add_argument('--value-2', nargs=4)
parser.add_argument('email', nargs='+')
args = parser.parse_args()

print(args)

then you can call your Python program as

python mytest.py [email protected]  --value-1 value of file 1  --value-2 value of file 2

And get the following result,

Namespace(email=['[email protected]'], value_1=['value', 'of', 'file', '1'], value_2=['value', 'of', 'file', '2'])

which you can then conveniently access as

print(args.value_1)
print(args.value_2)
print(args.email)
Answer from Victor on Stack Overflow
Top answer
1 of 2
5

First (and probably most preferable) solution is to put the second and third argument in quotes as Susmit Agrawal suggested. Then the shell itself will split the command line into arguments appropriately.

python mytest.py [email protected]  "value of file 1"  "value of file 2"

In case you really need to pass arguments without quotes though, you will have to accept that the shell will be splitting your second and third argument at spaces, so you will need to reconstruct them from sys.argv yourself.

Lastly, you may want to explore argparse library to help you with parsing the command line arguments. In this case you may want to use optional arguments with nargs set to '+' or some certain number based on your command line API. For example, if you define and parse your arguments the following way,

parser = argparse.ArgumentParser()
parser.add_argument('--value-1', nargs=4)
parser.add_argument('--value-2', nargs=4)
parser.add_argument('email', nargs='+')
args = parser.parse_args()

print(args)

then you can call your Python program as

python mytest.py [email protected]  --value-1 value of file 1  --value-2 value of file 2

And get the following result,

Namespace(email=['[email protected]'], value_1=['value', 'of', 'file', '1'], value_2=['value', 'of', 'file', '2'])

which you can then conveniently access as

print(args.value_1)
print(args.value_2)
print(args.email)
2 of 2
0

you can use argparse to pass your argument:

import argparse 

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-stv1', type=str)
    parser.add_argument('-stv2', type=str)
    parser.add_argument('-email', nargs='+')
    args = parser.parse_args()
    print(args)

nargs='+' indicate that at least you should pass one argument as email or more.

Executing the script give the following :

python3 script.py -email [email protected] [email protected] -stv1 "value of file 1" -stv2 "value of file 2" 

Namespace(email=['[email protected]', '[email protected]'], stv1='value of file 1', stv2='value of file 2')

๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_command_line_arguments.htm
Python - Command-Line Arguments
Here Python script name is script.py and rest of the three arguments - arg1 arg2 arg3 are command line arguments for the program. If the program needs to accept input from the user, Python's input() function is used.
Discussions

How to pass multiple arguments in command line using python - Stack Overflow
import csv import re import string ... print "Total Number of Symbols:\n",line.strip(' has '); getSymbols(filename) I have a requirement and I am not able to find a solution: How can I pass multiple file path as arguments in the command line ?... More on stackoverflow.com
๐ŸŒ stackoverflow.com
November 19, 2011
Best way to pass a ton of command line arguments into a Python application?
I don't understand your argparse comment. It does exactly what you want, easily. More on reddit.com
๐ŸŒ r/Python
27
13
November 16, 2017
list - Python pass multiple strings to a single command line argument - Stack Overflow
I am new to Python and barely know about lists and tuples. I have a program to execute which takes several values as input argument. Below is the list of input args parser = argparse.ArgumentParse... More on stackoverflow.com
๐ŸŒ stackoverflow.com
April 19, 2016
python - How do I access command line arguments? - Stack Overflow
I use python to create my project settings setup, but I need help getting the command line arguments. I tried this on the terminal: $python myfile.py var1 var2 var3 In my Python file, I want to u... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
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โ€ฆ
๐ŸŒ
Typer
typer.tiangolo.com โ€บ tutorial โ€บ multiple-values โ€บ arguments-with-multiple-values
CLI Arguments with Multiple Values - Typer
CLI arguments can also receive multiple values. You can define the type of a CLI argument using list. Python 3.10+ from pathlib import Path import typer app = typer.Typer() @app.command() def main(files: list[Path], celebration: str): for path in files: if path.is_file(): print(f"This file exists: {path.name}") print(celebration) if __name__ == "__main__": app() And then you can pass it as many CLI arguments of that type as you want: $ python main.py ./index.md ./first-steps.md woohoo!
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ executing-functions-with-multiple-arguments-at-a-terminal-in-python
Executing functions with multiple arguments at a terminal in Python - GeeksforGeeks
September 2, 2020 - The variables arg1, arg2 and arg3 are passed to the function defined. However, the command line arguments can be passed directly without storing its value in local variables.
๐ŸŒ
Reddit
reddit.com โ€บ r/python โ€บ best way to pass a ton of command line arguments into a python application?
r/Python on Reddit: Best way to pass a ton of command line arguments into a Python application?
November 16, 2017 -

I'm writing an application with a bunch of classes that interact with each other, and the client would like to be able to specify parameters through the command line. For example app num_people=1000 realtime=True outputdir='my/home/dir', but with far more options. The options will be in a variety of classes, and will have defaults if nothing is passed in.

What is the best way to do this in Python 3? I know about argparse but it seems like a potential framework I'll use to answer this question, not the actual solution.

Find elsewhere
๐ŸŒ
Real Python
realpython.com โ€บ python-command-line-arguments
Python Command-Line Arguments โ€“ Real Python
August 27, 2023 - Unless explicitly expressed at the command line with the option -o, a.out is the default name of the executable generated by the gcc compiler. It stands for assembler output and is reminiscent of the executables that were generated on older UNIX systems. Observe that the name of the executable ./main is the sole argument. Letโ€™s spice up this example by passing a few Python command-line arguments to the same program:
๐ŸŒ
Comptoolsres
comptoolsres.github.io โ€บ Argparse.html
Passing Command Line Arguments in Python with Argparse | Computational Tools for Research
Using a slight modification of the example from the tutorial, hereโ€™s a good example of passing in a floating point value: #!/usr/bin/env python # square.py: Demo of argparse import argparse parser = argparse.ArgumentParser() parser.add_argument("square", help="display a square of a given number", type=float) # Parse the command line arguments args = parser.parse_args() print(f"The square of {args.square} is {args.square**2}")
๐ŸŒ
Python
docs.python.org โ€บ 3.3 โ€บ library โ€บ argparse.html
16.4. argparse โ€” Parser for command-line options, arguments and sub-commands โ€” Python 3.3.7 documentation
Arguments read from a file must ... on the command line. So in the example above, the expression ['-f', 'foo', '@args.txt'] is considered equivalent to the expression ['-f', 'foo', '-f', 'bar']. The fromfile_prefix_chars= argument defaults to None, meaning that arguments will never be treated as file references. Generally, argument defaults are specified either by passing a default ...
๐ŸŒ
MachineLearningMastery
machinelearningmastery.com โ€บ home โ€บ blog โ€บ command line arguments for your python script
Command Line Arguments for Your Python Script - MachineLearningMastery.com
June 21, 2022 - When you run a command line with a more complicated set of arguments, it takes some effort to process the list sys.argv. Therefore, Python provided the library argparse to help. This assumes GNU-style, which can be explained using the following example: The optional arguments are introduced by โ€œ-โ€ or โ€œ--โ€œ, where a single hyphen will carry a single character โ€œshort optionโ€ (such as -a, -B, and -v above), and two hyphens are for multiple characters โ€œlong optionsโ€ (such as --exclude and --ignore-existing above).
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ command-line-arguments-in-python
Command Line Arguments in Python - GeeksforGeeks
Note: As a default optional argument, it includes -h, along with its long version --help. Example 1: Basic use of argparse module. ... Example 2: Adding description to the help message. ... # Python program to demonstrate # command line arguments import argparse msg = "Adding description" # Initialize parser parser = argparse.ArgumentParser(description = msg) parser.parse_args()
Published ย  March 17, 2025
๐ŸŒ
CopyProgramming
copyprogramming.com โ€บ howto โ€บ mastering-python-how-to-pass-multiple-arguments-at-the-command-line
Mastering Python: How to Pass Multiple Arguments at the Command Line - Python pass multiple arguments command line
January 25, 2023 - If you pass command line arguments ... using predetermined formal parameters in the function definition. You can use the *args parameter to pass a variable number of non-keyword arguments to a function....
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python โ€บ command line arguments
Python | Command Line Arguments | Codecademy
September 26, 2025 - However, common argument types ... and version arguments. To pass arguments to a Python script, include them after the script name when running it: python script.py argument1 argument2 - passes multiple argume...
๐ŸŒ
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 - In Python, command-line arguments are accessed through the sys.argv list. The first item in the list is always the name of the script itself, and subsequent items are the arguments passed to the script.
๐ŸŒ
Codecademy
codecademy.com โ€บ article โ€บ command-line-arguments-in-python
Command Line Arguments in Python (sys.argv, argparse) | Codecademy
For smaller scripts, sys.argv may suffice, but for more advanced use cases involving multiple options, flags, and input validation, methods like getopt and argparse offer more structure and flexibility. Here is a table that summarizes the key differences between sys.argv. getopt and argparse: Command-line arguments in Python let you customize how your scripts run without changing the code itself.