Python Arguments With Argparse

The aim of this playbook🏁 is to try to standardize a simple use of argparse module in Python for passing named arguments from CLI (PowerShell in my case). This is used mostly within PowerShell scripts to improve readability.

1. steps/notes

  1. import argparse module
  • e.g. python --param1="foo" --param2=="bar"
import argparse

def function_proper(param1, param2) -> None:

def init_argparse() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser()
return parser

def main() -> None:
parser = init_argparse()
args = parser.parse_args()
function_proper(param1=args.param1, param2=args.param2)

if __name__ == "__main__":

Technical Support Engineer of Behavioural Data Platform (Snowplow Analytics). On comparison of programming languages, history of computing, and raw playbooks.