Re: Writing to stdout
Robin Becker <[email protected]> Sun, 28 Feb 2021 19:58:01 +0000
| Newsgroups | gmane.comp.python.reportlab.user |
|---|---|
| Message-ID | <[email protected]> |
I think this is almost the right answer Christof, but since PDF is not a textual file format I think the correct way to overcome the python3 encode everything is to use the buffer directly eg sys.stdout.buffer is a binary file see https://docs.python.org/3.9/glossary.html#term-binary-file so rob you should use c = canvas.Canvas(sys.stdout.buffer) On 28/02/2021 18:40, Christoph Zwerschke wrote: > On 28.02.2021 18:55, Rob Allen wrote: > > This is what happens when I run it: > > > > ... > > TypeError: write() argument must be str, not bytes > > > This is probably because stdout is expecting text (native strings), but ReportLab sends bytes. > > It may work when replacing sys.stdout with something like TextIOWrapper(sys.stdout.buffer, encoding='utf8'). > > -- Christoph > _______________________________________________ > reportlab-users mailing list > [email protected] > https://pairlist2.pair.net/mailman/listinfo/reportlab-users -- Robin Becker