當(dāng)前位置:首頁 > IT技術(shù) > 編程語言 > 正文

Python 實(shí)現(xiàn) cat
2021-10-28 15:20:47

import argparse
parser = argparse.ArgumentParser()

parser.add_argument('files', metavar='F', type=str, nargs='+')
parser.add_argument('-n', '--numbers', action='store_true',
        help='Print line numbers')

args = parser.parse_args()

print(">>> parsed args: ", args)

line_number = 1
for in_file_name in args.files:
    in_file = open(in_file_name)
    if args.numbers:
        for line in in_file.readlines():
            print(f"	{line_number}	{line}", end="")
            line_number += 1
    else:
        print(in_file.read())

?

本文摘自 :https://blog.51cto.com/u

開通會(huì)員,享受整站包年服務(wù)立即開通 >