From 76996a8827ec1197dec5044c50a328ab4c852c3b Mon Sep 17 00:00:00 2001 From: James McKinney <26463+jpmckinney@users.noreply.github.com> Date: Tue, 17 Oct 2023 22:39:35 -0400 Subject: [PATCH] fix: Reconfigure the encoding of standard input according to the --encoding option, closes #1038 --- CHANGELOG.rst | 1 + csvkit/cli.py | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 37310b31f..c5e191514 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -10,6 +10,7 @@ Unreleased * :doc:`/scripts/csvstat` adds a :code:`--non-nulls` option to only output counts of non-null values. * :doc:`/scripts/csvstat` adds a :code:`--max-precision` option to only output the most decimal places. * feat: Add a :code:`--null-value` option to commands with the :code:`--blanks` option, to convert additional values to NULL. +* fix: Reconfigure the encoding of standard input according to the :code:`--encoding` option, which defaults to ``utf-8-sig``. Affected users no longer need to set the ``PYTHONIOENCODING`` environment variable. * fix: Prompt the user if additional input is expected (i.e. if no input file or piped data is provided) in :doc:`/scripts/csvjoin`, :doc:`/scripts/csvsql` and :doc:`/scripts/csvstack`. * fix: No longer errors if a NUL byte occurs in an input file. * Add Python 3.12 support. diff --git a/csvkit/cli.py b/csvkit/cli.py index e62a066a9..0681e07cc 100644 --- a/csvkit/cli.py +++ b/csvkit/cli.py @@ -238,6 +238,7 @@ def _open_input_file(self, path): Open the input file specified on the command line. """ if not path or path == '-': + sys.stdin.reconfigure(encoding=self.args.encoding) f = sys.stdin else: extension = splitext(path)[1]