Don't reinvent the wheel. Use the argparse module, be explicit and pass in actual lists of parameters

import argparse
# defined command line options
# this also generates --help and error handling
CLI=argparse.ArgumentParser()
CLI.add_argument(
  "--lista",  # name on the CLI - drop the `--` for positional/required parameters
  nargs="*",  # 0 or more values expected => creates a list
  type=int,
  default=[1, 2, 3],  # default if nothing is provided
)
CLI.add_argument(
  "--listb",
  nargs="*",
  type=float,  # any type/callable can be used here
  default=[],
)

# parse the command line
args = CLI.parse_args()
# access CLI options
print("lista: %r" % args.lista)
print("listb: %r" % args.listb)

You can then call it using

$ python my_app.py --listb 5 6 7 8 --lista  1 2 3 4
lista: [1, 2, 3, 4]
listb: [5.0, 6.0, 7.0, 8.0]
Answer from user5349916 on Stack Overflow
Top answer
1 of 9
154

Don't reinvent the wheel. Use the argparse module, be explicit and pass in actual lists of parameters

import argparse
# defined command line options
# this also generates --help and error handling
CLI=argparse.ArgumentParser()
CLI.add_argument(
  "--lista",  # name on the CLI - drop the `--` for positional/required parameters
  nargs="*",  # 0 or more values expected => creates a list
  type=int,
  default=[1, 2, 3],  # default if nothing is provided
)
CLI.add_argument(
  "--listb",
  nargs="*",
  type=float,  # any type/callable can be used here
  default=[],
)

# parse the command line
args = CLI.parse_args()
# access CLI options
print("lista: %r" % args.lista)
print("listb: %r" % args.listb)

You can then call it using

$ python my_app.py --listb 5 6 7 8 --lista  1 2 3 4
lista: [1, 2, 3, 4]
listb: [5.0, 6.0, 7.0, 8.0]
2 of 9
26

Command line arguments are always passed as strings. You will need to parse them into your required data type yourself.

>>> input = "[2,3,4,5]"
>>> map(float, input.strip('[]').split(','))
[2.0, 3.0, 4.0, 5.0]
>>> A = map(float, input.strip('[]').split(','))
>>> print(A, type(A))
([2.0, 3.0, 4.0, 5.0], <type 'list'>)

There are libraries like argparse and click that let you define your own argument type conversion but argparse treats "[2,3,4]" the same as [ 2 , 3 , 4 ] so I doubt it will be useful.

edit Jan 2019 This answer seems to get a bit of action still so I'll add another option taken directly from the argparse docs.

You can use action=append to allow repeated arguments to be collected into a single list.

>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('--foo', action='append')
>>> parser.parse_args('--foo 1 --foo 2'.split())
Namespace(foo=['1', '2'])

In this case you would pass --foo ? once for each list item. Using OPs example: python filename.py --foo 2 --foo 3 --foo 4 --foo 5 would result in foo=[2,3,4,5]

🌐
Python
docs.python.org › 3 › using › cmdline.html
1. Command line and environment — Python 3.15.0 documentation
When called with -c command, it executes the Python statement(s) given as command. Here command may contain multiple statements separated by newlines. When called with -m module-name, the given module is located using the standard import mechanism and executed as a script. In non-interactive mode, the entire input is parsed before it is executed. An interface option terminates the list of options consumed by the interpreter, all consecutive arguments will end up in sys.argv – note that the first element, subscript zero (sys.argv[0]), is a string reflecting the program’s source.
🌐
Python Morsels
pythonmorsels.com › cli-tools
Python's many command-line utilities - Python Morsels
June 3, 2024 - The Python standard library includes many such module-script hybrids. Below is a complete list of every module in Python that can be run as a command-line script.
🌐
Reddit
reddit.com › r/learnpython › my first cli to-do list app in python (no classes, no files—just functions & lists!)
r/learnpython on Reddit: My First CLI To-Do List App in Python (No Classes, No Files—Just Functions & Lists!)
April 25, 2025 -
Tasks = []



def show_menu():
    print("""
===== TO-DO LIST MENU =====
1. Add Task
2. View Tasks
3. Mark Task as Complete
4. Delete Task
5. Exit
""")



def add_task():
    task_description = input("Enter task Description: ")
    Tasks.append(task_description)

def view_tasks():
    for index, item in enumerate(Tasks):
        print(f"{index} -> {item}")


def mark_task_complete():
    choice = int(input("Which task number do you want to mark as complete: "))
    index = choice-1
    Tasks[index] ='\u2713'



def delete_task():
    choice = int(input("Which Tasks Do you want to delete?: "))
    index = choice -1
    if index >= 0 and index < len(Tasks):
            Tasks.pop(index) 
            print("Task deleted successfully.")
    else:
            print("Invalid task number.")
    

while True:
     show_menu()
     choice = input("Enter your choice: ")

     if choice == "1":
          add_task()
     elif choice == "2":
          view_tasks()
     elif choice == "3":
          mark_task_complete()
     elif choice == "4":
          delete_task()
     elif choice == "5":
          print("Good bye")
          break
     else:
          print("Invalid choice, Please try again")
           

what should i add or how should make it advanced or is it enough for a begginer,
i am just a begginer who just learned functions and lists and tried this one project

🌐
Medium
medium.com › the-pythonworld › 8-python-cli-tools-i-never-knew-i-needed-until-i-used-them-21008ebf5d0b
8 Python CLI Tools I Never Knew I Needed (Until I Used Them) | by mata | The Pythonworld | Medium
April 20, 2026 - The magic of Typer is that your CLI code reads like normal Python. No learning a framework-specific DSL, no decorator soup. If you know type hints, you already know Typer. The documentation mirrors FastAPI’s style — clean, example-driven, and thorough. This one’s the newest tool on my list, and it might be the one I’m most excited about.
Find elsewhere
🌐
Medium
medium.com › @wilson79 › 10-best-python-cli-libraries-for-developers-picking-the-right-one-for-your-project-cefb0bd41df1
10+ Best Python CLI Libraries for Developers: Picking the Right One for Your Project | by Wilson | Medium
February 3, 2026 - Shows multiple CLI libraries (Rich, TQDM, Typer) exactly as discussed in your article. It’s 11:24 PM on a Thursday. You’ve been staring at your terminal for the past hour, trying to figure out why your Python script keeps throwing cryptic errors when users enter the wrong input.
🌐
Real Python
realpython.com › python-typer-cli
Build a Command-Line To-Do App With Python and Typer – Real Python
July 3, 2026 - Building an application to manage your to-do list can be an interesting project when you’re learning a new programming language or trying to take your skills to the next level. In this tutorial, you’ll build a functional to-do application for the command line using Python and Typer, which is a relatively young library for creating powerful command-line interface (CLI) applications in almost no time.
🌐
Python
docs.python.org › 3 › library › cmdline.html
Modules command-line interface (CLI) — Python 3.15.0 documentation
The Python standard library » · Modules command-line interface (CLI) | Theme · Auto · Light · Dark | The following modules have a command-line interface. ast · asyncio · base64 · calendar · code · compileall · cProfile: see profiling.tracing · dis · doctest ·
🌐
Python
docs.python.org › 3 › library › cmdlinelibs.html
Command-line interface libraries — Python 3.15.0 documentation
The modules described in this chapter assist with implementing command line and terminal interfaces for applications. Here’s an overview: argparse — Parser for command-line options, arguments and s...
🌐
Medium
medium.com › @noransaber685 › simple-guide-to-creating-a-command-line-interface-cli-in-python-c2de7b8f5e05
Simple Guide to Creating a Command-Line Interface (CLI) in Python | by Noran Saber Abdelfattah | Medium
February 3, 2024 - Type "help" for available commands.' def __init__(self): super().__init__() self.current_directory = os.getcwd() def do_list(self, line): """List files and directories in the current directory.""" files_and_dirs = os.listdir(self.current_directory) for item in files_and_dirs: print(item) def do_change_dir(self, directory): """Change the current directory.""" new_dir = os.path.join(self.current_directory, directory) if os.path.exists(new_dir) and os.path.isdir(new_dir): self.current_directory = new_dir print(f"Current directory changed to {self.current_directory}") else: print(f"Directory '{dir
🌐
pytz
pythonhosted.org › pyCLI
cli — command line tools — pyCLI devel documentation
The cli package is a framework for making simple, correct command line applications in Python. With cli, you can quickly add standard command line parsing; logging; unit and functional testing; and profiling to your CLI apps.
🌐
GitHub
github.com › cdeil › python-cli-examples
GitHub - cdeil/python-cli-examples: Examples exploring Python command line interface (CLI) packages · GitHub
The cli is part of a Python package, exposed both via a setuptools entry point and __main__.py, i.e. Just calling the main cli should print some help, i.e. a list of main cli arguments and available subcommands (like how git and git --help print the same thing).
Author: cdeil
🌐
DEV Community
dev.to › usooldatascience › mastering-command-line-interfaces-cli-in-python-a-comprehensive-guide-10bc
Mastering Command-Line Interfaces (CLI) in Python: A Comprehensive Guide - DEV Community
September 15, 2024 - typer: A modern library built on top of click, which uses Python type hints for ease of use. sys.argv is a basic way to access command-line arguments. It stores the command-line arguments as a list, where the first element is always the script name.
🌐
Stack Abuse
stackabuse.com › generating-command-line-interfaces-cli-with-fire-in-python
Generating Command-Line Interfaces (CLI) with Fire in Python
September 20, 2023 - Google's Python Fire library makes it easy to add a CLI processing component to any existing Python script. Let's see how to make a command line application using Python Fire. ... Python Fire works on any Python object i.e. functions, classes, dictionaries, lists etc.