Do I need to close?

Fredrik Lundh fredrik at pythonware.com
Tue Oct 28 15:44:47 EST 2003


Derek Fountain wrote:

> 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>








More information about the Python-list mailing list