pythonic way to free resources

Greg Ewing see_reply_address at something.invalid
Tue Aug 20 03:17:13 CEST 2002


Another possibility:

   class NoFile:
     def close(self):
       pass

   f = NoFile()
   g = NoFile()
   h = NoFile()
   try:
      # stuff that opens f, g and/or h
   finally:
     f.close()
     g.close()
     h.close()

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list