[reportlab-users] Puzzling Error - Solved!

Engel, Gregory reportlab-users@reportlab.com
Tue, 5 Nov 2002 11:20:44 -0700


This was exactly the solution!  Thanks Andy...


> exceptions.AttributeError
> 'unicode' object has no attribute 'write'
> <traceback object at 0x0328A4D0>

My guess is you are passing a unicode string as a filename
and not an 8-bit python string.  Currently we cannot easily test
for unicode as we have to run on pre-Unicode versions of
Python. =20

The relevant code is in pdfdoc, class PDFDocument, method saveToFile
and does this!

 if type(filename) is StringType:
            myfile =3D 1
            f =3D open(filename, "wb")
        else:
            myfile =3D 0
            f =3D filename # IT BETTER BE A FILE-LIKE OBJECT!

So if you pass a Unicode string it assumes it's something
writable.

Solution:  either do=20
   filename =3D str(filename)
in your code before setting up the canvas, or explicitly pass
in an open file object.

HTH,

Andy Robinson