cmc/learn
My personal learning area.
clone: git clone https://gitbay.org/cmc/learn.git
1import argparse
2
3# Create an argument parser to obtain file name
4parser = argparse.ArgumentParser(description='cat')
5parser.add_argument('-f', '--file', help='File name')
6args = parser.parse_args()
7
8# Open the file using the `file` argument
9path = args.file
10with open(path, 'r') as file:
11 # Read and print the file contents
12 contents = file.read()
13 print(contents)