PIL: Do I need to close?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Derek Fountain

    PIL: Do I need to close?

    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?
  • Fredrik Lundh

    #2
    Re: Do I need to close?

    Derek Fountain wrote:
    [color=blue]
    > 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?[/color]

    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>




    Comment

    • Derek Fountain

      #3
      Re: Do I need to close?

      > PIL works with image objects, not files. It automagically closes the[color=blue]
      > file when it doesn't need it any more.[/color]

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

      Oh, I trust it. Really!

      Thanks!

      Comment

      Working...