How to pass a parameter to a Python script when run from the command line or shell script

note to self: work on shorter titles.

import sys

my_variable_name = sys.argv[1] # first argument

Example:

# test.py

import sys

print(f"Is your name Paul {sys.argv[1]}?")
python3 test.py "Atreides"

⬇︎

Is your name Paul Atreides?

links

social