I want to open file for reading using argparse. In cmd it must look like: my_program.py /filepath
That\'s my try:
parser = argparse.ArgumentParser()
I'll just add the option to use pathlib:
pathlib
import argparse, pathlib parser = argparse.ArgumentParser() parser.add_argument('file', type=pathlib.Path) args = parser.parse_args() with args.file.open('r') as file: print(file.read())