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
Remove unused argument
  • Loading branch information
Rémi Lapeyre committed Feb 26, 2019
commit 67e2116da7ec7be170c468241a640895fa1ad596
6 changes: 3 additions & 3 deletions Lib/json/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _open_outfile(outfile, parser):
except IOError as e:
parser.error(f"can't open '{outfile}': {str(e)}")

def _write(parser, outfile, objs, sort_keys):
def _write(outfile, objs, sort_keys):
for obj in objs:
json.dump(obj, outfile, sort_keys=sort_keys, indent=4)
outfile.write('\n')
Expand Down Expand Up @@ -70,13 +70,13 @@ def main():
outfile = _open_outfile(outfile, parser)

with outfile:
_write(parser, outfile, objs, sort_keys)
_write(outfile, objs, sort_keys)

else:
outfile = _open_outfile(outfile, parser)
with infile, outfile:
objs = _read(infile, json_lines)
_write(parser, outfile, objs, sort_keys)
_write(outfile, objs, sort_keys)

if __name__ == '__main__':
main()
0