[reportlab-users] io.StringIO vs cStringIO.StringIO

Michael Hipp michael at redmule.com
Tue Oct 11 15:49:09 EDT 2011


It appears the 'cStringIO' module is being depreciated in favor of the 'io'
module going forward to Py3.

In Py2.7, this works:
from cStringIO import StringIO
out = StringIO() # write it to a memory buffer
doc = SimpleDocTemplate(out, ...)

But this doesn't:
from io import StringIO
...

I thought the io.StringIO was a drop-in replacement, but it gives this exception:

TypeError: string argument expected, got 'str'
...
File "C:\Python27\Lib\site-packages\reportlab\pdfbase\pdfdoc.py", line 235, in
SaveToFile
f.write(self.GetPDFData(canvas))

The thing returned by self.GetPDFData(canvas) is indeed of type 'str' but the
io.StringIO object doesn't seem to like it. Any ideas?

Reportlab 2.5, Win7x32, Py2.7.

Thanks,
Michael Hipp


More information about the reportlab-users mailing list