Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78200 > unrolled thread
| Started by | Frank Liou <fk26541598fk@gmail.com> |
|---|---|
| First post | 2014-09-23 01:29 -0700 |
| Last post | 2014-09-23 07:03 -0400 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
PIL can't read binary Frank Liou <fk26541598fk@gmail.com> - 2014-09-23 01:29 -0700
Re: PIL can't read binary Chris Angelico <rosuav@gmail.com> - 2014-09-23 18:36 +1000
Re: PIL can't read binary Ned Batchelder <ned@nedbatchelder.com> - 2014-09-23 07:03 -0400
| From | Frank Liou <fk26541598fk@gmail.com> |
|---|---|
| Date | 2014-09-23 01:29 -0700 |
| Subject | PIL can't read binary |
| Message-ID | <2bae5b6f-a3b9-40d8-a037-a6ff309ba71f@googlegroups.com> |
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
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-09-23 18:36 +1000 |
| Message-ID | <mailman.14249.1411461377.18130.python-list@python.org> |
| In reply to | #78200 |
On Tue, Sep 23, 2014 at 6:29 PM, Frank Liou <fk26541598fk@gmail.com> 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 I suspect a lot of this ought to be in a method, probably __init__, rather than raw in the class definition. However, the problem here is that your Image is a list (as indicated by the exception), and you probably want to open just one of its elements - maybe Image[0].open(...). You may also want to iterate over the entire list, which would cope better with the possibility of having none or multiple. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Date | 2014-09-23 07:03 -0400 |
| Message-ID | <mailman.14255.1411470254.18130.python-list@python.org> |
| In reply to | #78200 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web