PIL: Do I need to close?

D

Derek Fountain

I've just started looking at the PIL module. There doesn't seem to be a
close method. Is that right? I just open the image file, and never need to
close it?
 
F

Fredrik Lundh

Derek said:
I've just started looking at the PIL module. There doesn't seem to be a
close method. Is that right? I just open the image file, and never need to
close it?

PIL works with image objects, not files. It automagically closes the
file when it doesn't need it any more.

If you don't trust PIL, do this:

fp = open(filename, "rb")
im = Image.open(fp) # open from file object
im.load() # make sure PIL has read the data
fp.close()

</F>
 
D

Derek Fountain

PIL works with image objects, not files. It automagically closes the
file when it doesn't need it any more.

Ah, OK. As a Python newbie, it's these details I still need to think through
properly.
If you don't trust PIL, do this:

Oh, I trust it. Really!

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,459
Latest member
Vida00R129

Latest Threads

Top