pythonic way to free resources

Greg Ewing see_reply_address at something.invalid
Mon Aug 19 21:17:13 EDT 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