views:

258

answers:

2

Hi, i am trying to do something with the PIL Image library in django, but i experience some problems.

I do like this:

import Image

And then I do like this

images = map(Image.open, glob.glob(os.path.join(dirpath, '*.thumb.jpg')))

But when i try to run this i get an error and it leeds me to think that its not imported correctly, anybody know?

type object 'Image' has no attribute 'open'

A: 

Your example works fine in my machine. I don't know why you're getting that error. PIL documentation say you have to import the library in this way:

from PIL import Image

You should try that way. As I said, for me works in both ways.

Manuel Ceron
+1  A: 

The error above happens because your file is called Image.py and you're trying to import yourself. As Manual pointed out, you should import Image from the PIL module, but you'd also need to rename your file so it's not called Image.py.

Johan Dahlin
Aha, my file isnt called Image.py but Ive got a django Model in the file wich is called Image, that is proporbly the reason, i'll have to try that thanks.
Espen Christensen
Works great, I just put my function in an external file and imported it in. Thanks.
Espen Christensen