fork download
  1. import argparse
  2.  
  3. def main():
  4. parser = argparse.ArgumentParser('py')
  5. parser.add_argument('file', help='input file')
  6. parser.add_argument('encoding', help='encoding')
  7. args = parser.parse_args()
  8.  
  9. with open(args.file, 'r', encoding=args.encoding) as fin:
  10. lines = fin.readlines()
  11.  
  12. for line in lines:
  13. if line.startswith('title:'):
  14. title = line.split(':')[1].strip()
  15. print('Title:', title)
  16. elif line.startswith('author:'):
  17. author = line.split(':')[1].strip()
  18. print('Author:', author)
  19.  
  20. main()
Runtime error #stdin #stdout #stderr 0.05s 11032KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
usage: py [-h] file encoding
py: error: the following arguments are required: file, encoding