def require_open(func):
 def wrapper(self, *args, **kwargs):
  if self.closed:
   raise IOError(errno.EBADF, 'I/O operation on closed file')
  return func(self, *args, **kwargs)
 return wrapper

def require_open ( func ) : def wrapper ( self , * args , ** kwargs ) : if self . closed : raise IOError ( errno . EBADF , 'I/O operation on closed file' ) return func ( self , * args , ** kwargs ) return wrapper
decorator that ensures that the file instance isnt closed when the function is run .