#! /home/phd/.local/bin/python3 "Recode to default charset" import sys from recode_filenames import parse_args from_encoding, to_encoding, files = parse_args(default='-') output = getattr(sys.stdout, 'buffer', sys.stdout) if files != ['-']: for file in files: with open(file, 'rb') as infile: for line in infile: output.write( line.decode(from_encoding, "replace"). encode(to_encoding, "replace")) else: input = getattr(sys.stdin, 'buffer', sys.stdin) for line in input: output.write( line.decode(from_encoding, "replace"). encode(to_encoding, "replace") )