Python 基礎學習

  • 執行 .py
python basic.py
  • 執行時添加必要參數

https://replit.com/@k1319900103/Start#basic3.pyopen in new window

import argparse

parser = argparse.ArgumentParser(description='this is desc..')

parser.add_argument('-c',
                    '--color',
                    metavar='color',
                    required=True,
                    choices={'red', 'yellow'},
                    help='set a color as parameter')

args = parser.parse_args()

print(args.color)