8000 bpo-33927: Add support for same infile and outfile to json.tool by remilapeyre · Pull Request #7865 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-33927: Add support for same infile and outfile to json.tool #7865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Prev Previous commit
Next Next commit
Always open outfile with utf-8
  • Loading branch information
remilapeyre committed May 28, 2020
commit f99c54cf66a730d1a4dd88d248ecb849f742c78a
5 changes: 4 additions & 1 deletion Lib/json/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ def _read(infile, json_lines):

def _open_outfile(outfile, parser):
try:
return sys.stdout if outfile == '-' else open(outfile, 'w')
if outfile == '-':
return sys.stdout
else:
return open(outfile, 'w', encoding='utf-8')
except IOError as e:
parser.error(f"can't open '{outfile}': {str(e)}")

Expand Down
0