I'm using PyQRCode [0] to generate a QR in PNG format under Python 2.7.6.
When I try to write a file on disk using all works ok:
import pyqrcode
from io import BytesIO
qr = pyqrcode.create("my qr string", mode='binary', version=7)
qr.png("myqr.png", scale=4)
But when I try to use a io stream using this code:
import pyqrcode
from io import BytesIO
qr = pyqrcode.create("my qr string", mode='binary', version=7)
f=BytesIO()
qr.png(f, scale=4)
f.getvalue()
I get on the f.getvalue()
line:
Traceback (most recent call last):
File "<input>", line 1, in <module>
ValueError: I/O operation on closed file.
The PyQRCode documentation says that the file
parameter could be a writeable stream.
I tried hard to debug this but I can't find where the stream is being closed and there is not any .close() statement for the stream. [1]
[0] https://pypi.python.org/pypi/PyQRCode
[1] http://pythonhosted.org//PyQRCode/_modules/pyqrcode.html#QRCode.png