aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Stasiak <jakub@stasiak.at>2020-02-08 13:52:06 +0100
committerJakub Stasiak <jakub@stasiak.at>2020-02-08 13:52:06 +0100
commite946ac7cdb4e61458502da629d79d78cac22d060 (patch)
treee1d68134c4b697240d5a296c7f0d2f83f27e0f50
parent0e4eb9bff3763d3372f23b27f9c2390705e2d962 (diff)
downloadscreenplain-e946ac7cdb4e61458502da629d79d78cac22d060.tar.gz
Fix "TypeError: write() argument must be str, not bytes" on Python 3
This used to happen when writing to stdout. On Python 3 stdout is an instance of TextIOWrapper which is a text-based interface. It wraps a bytes-based writer though which is accessible through the buffer attribute, so let's use that to either write to it directly or to get an encoding writer. Fixes https://github.com/vilcans/screenplain/issues/53.
-rw-r--r--screenplain/main.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/screenplain/main.py b/screenplain/main.py
index 770427c..313498f 100644
--- a/screenplain/main.py
+++ b/screenplain/main.py
@@ -109,9 +109,9 @@ def main(args):
output = open(output_file, 'wb')
else:
if output_encoding:
- output = codecs.getwriter(output_encoding)(sys.stdout)
+ output = codecs.getwriter(output_encoding)(sys.stdout.buffer)
else:
- output = sys.stdout
+ output = sys.stdout.buffer
try:
if format == 'text':