-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use python iconv if system iconv is broken (#1156)
* use python iconv if system iconv is broken * black
- Loading branch information
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/python3 | ||
|
||
import argparse | ||
import sys | ||
|
||
parser = argparse.ArgumentParser(description="Convert a file from one encoding to another") | ||
parser.add_argument("f") | ||
parser.add_argument("t") | ||
parser.add_argument("infile", nargs="?", type=argparse.FileType("r"), default=sys.stdin) | ||
parser.add_argument("outfile", nargs="?", type=argparse.FileType("w"), default=sys.stdout) | ||
|
||
args = parser.parse_args() | ||
|
||
|
||
def main(args): | ||
sys.stdin.reconfigure(encoding=args.f) | ||
in_data = args.infile.read() | ||
sys.stdout.reconfigure(encoding=args.t) | ||
args.outfile.write(in_data) | ||
|
||
|
||
if __name__ == "__main__": | ||
main(parser.parse_args()) |