[reportlab-users] Writing to stdout
Rob Allen
rob at akrabat.com
Sun Feb 28 12:55:50 EST 2021
Hi,
I’m trying to write to stdout and it’s not working.
I’m using Python 3.8.6 with a clean virtualenv into which I ran `pip install reportlab`.
$ python --version
Python 3.8.6
$ pip freeze
Pillow==8.1.0
reportlab==3.5.59
This is my test application, based on page 11 of the manual where I changed the filename to sys.stdout:
$ cat test.py
import sys
from reportlab.pdfgen import canvas
def hello(c):
c.drawString(100, 100, "Hello World")
c = canvas.Canvas(sys.stdout)
hello(c)
c.showPage()
c.save()
This is what happens when I run it:
$ python test.py
Traceback (most recent call last):
File "test.py", line 10, in <module>
c.save()
File "/Users/rob/.pyenv/versions/py386/lib/python3.8/site-packages/reportlab/pdfgen/canvas.py", line 1277, in save
self._doc.SaveToFile(self._filename, self)
File "/Users/rob/.pyenv/versions/py386/lib/python3.8/site-packages/reportlab/pdfbase/pdfdoc.py", line 222, in SaveToFile
f.write(data)
TypeError: write() argument must be str, not bytes
Am I specifying the stdout stream incorrectly or missing something else?
Regards,
Rob
--
Development thoughts at https://akrabat.com
Daily Jotter for macOS at https://dailyjotter.com
rst2pdf: https://rst2pdf.org
More information about the reportlab-users
mailing list