Created
September 15, 2019 19:46
-
-
Save uda/44a509f2e9f3871575db1dde4d88a9a6 to your computer and use it in GitHub Desktop.
Convert file contents from one encoding to another
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
def trevnoc(source, target, source_encoding, target_encoding): | |
with open(source, 'r', encoding=source_encoding) as f: | |
content = f.read() | |
with open(target, 'w', encoding=target_encoding) as f: | |
f.write(content) | |
if __name__ == '__main__': | |
from argparse import ArgumentParser | |
parser = ArgumentParser('trevnoc') | |
parser.add_argument('source') | |
parser.add_argument('--from-encoding', '-f', default='ascii') | |
parser.add_argument('target') | |
parser.add_argument('--to-encoding', '-t', default='utf-8') | |
args = parser.parse_args() | |
trevnoc(args.source, args.target, args.from_encoding, args.to_encoding) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment