my_compiler.py 606 B

12345678910111213141516171819202122
  1. #!/usr/bin/env python3
  2. import os
  3. import sys
  4. assert(os.path.exists(sys.argv[3]))
  5. args = sys.argv[:-1]
  6. if __name__ == '__main__':
  7. if len(args) != 3 or not args[1].startswith('--input') or \
  8. not args[2].startswith('--output'):
  9. print(args[0], '--input=input_file --output=output_file')
  10. sys.exit(1)
  11. with open(args[1].split('=')[1]) as f:
  12. ifile = f.read()
  13. if ifile != 'This is a text only input file.\n':
  14. print('Malformed input')
  15. sys.exit(1)
  16. with open(args[2].split('=')[1], 'w') as ofile:
  17. ofile.write('This is a binary output file.\n')