PIL can't read binary
Ned Batchelder
ned at nedbatchelder.com
Tue Sep 23 07:03:58 EDT 2014
On 9/23/14 4:29 AM, Frank Liou wrote:
> I use PIL Image.open()
>
> but it show 'list' object has no attribute 'open'
>
> this is my code
>
> class Image2():
> trans = connection.begin()
> session = Session()
> ProductId = session.query(ProductEntity.ProductId).filter(ProductEntity.CompanyId=="2").all()
> Image = session.query(ProductImageGalleryEntity).filter(ProductImageGalleryEntity.ProductId=="20").all()
> PicFromDataBase = Image[0].ProductImage
> try:
> b = Image.open(str(PicFromDataBase))
> except Exception as e:
> sad = e
Image is the name of the PIL module, but you've reassigned it to be a
list. Try this:
images =
session.query(ProductImageGalleryEntity).filter(ProductImageGalleryEntity.ProductId=="20").all()
PicFromDataBase = images[0].ProductImage
try:
b = Image.open(str(PicFromDataBase))
except Exception as e:
sad = e
Also, I'll second Chris' point that this code should not be in the body
of the class, but in a method, or perhaps just a plain-old function.
--
Ned Batchelder, http://nedbatchelder.com
More information about the Python-list
mailing list