CLI Python Argparse

Python provides a way to build command which works like bash but you have leverage to python.

python pvt.py --help
python pvt.py tradedump out
import pandas as pd
import argparse

parser  = argparse.ArgumentParser()
parser.add_argument("tradedump", help="provide csv file of the external trade dump.")
parser.add_argument("out", help="output file names for pivot results.")
args    = parser.parse_args()
#defines input parameters
#path to trade dump
tradedump   = args.tradedump
output      = args.out

export_path=r"path/to/directory"
out_instrument  = export_path + f"\{output}_pvt_instruments.xlsx"
out_counterprt  = export_path + f"\{output}_pvt_counterparts.xlsx"
out_entities    = export_path + f"\{output}_pvt_entities.xlsx"

Reference:

Published by

wofong

三千娑婆世界,三千难忘遗憾;回头乃是岸,此岸在何方;堪忍不能忍,万般看不穿;何时放得下,始得自在心。 I'm a programmer, a quantitative analyst, a photography hobbyist, a traveler, a runner, and a nature lover.

Leave a comment