import sys def convert_file(input_filename, output_filename, converter): with open(input_filename, 'rb') as input_file: content = input_file.read() output = converter(content) with open(output_filename, 'wb+') as output_file: output_file.write(output) def main(from_ext, to_ext, converter): del sys.argv[0] if len(sys.argv) == 0: print("error: no input files!", file=sys.stderr) exit(1) for input_filename in sys.argv: output_filename = input_filename.removesuffix(f".{from_ext}") + f".{to_ext}" convert_file(input_filename, output_filename, converter)