I started argparse. It's so easy ...
So, I wrote the minimum code to check the shape of the argument.
I often forget how to call the code that I left behind. It's easy if it can be done with this much.
rem Call without arguments for the time being → Naturally an error → So usage is displayed
...\work> python argparse_sample.py
usage: python argparse_sample.py -input (inputfilepath) -output (outputfilepath)
argparse_sample.py: error: the following arguments are required: -input, -output
Execute rem usage as it is
...\work> python argparse_sample.py -input (inputfilepath) -output (outputfilepath)
inputfilepath=[(inputfilepath)]
outputfilepath=[(outputfilepath)]
def main():
import argparse
parser = argparse.ArgumentParser(
prog='argparse_sample.py',
usage='python argparse_sample.py -input (inputfilepath) -output (outputfilepath)'
)
parser.add_argument('-input', required=True)
parser.add_argument('-output', required=True)
args = parser.parse_args()
inputfilepath = args.input
outputfilepath = args.output
print(f'inputfilepath=[{inputfilepath}]')
print(f'outputfilepath=[{outputfilepath}]')
if __name__ == '__main__':
main()
Finally, maybe. I wanted such a function, and finally I started to think "Look for it!". I haven't had the habit of relying on external resources such as libraries made by other companies for a long time, so I finally started to think "search!" Instead of "make!". Well ... I think it's creating a new natural thing for me.
Recommended Posts