redawgts wrote: > I keep getting this error "local variable 'f' referenced before > assignment" in the finally block when I run the following code. > > try: > f = file(self.filename, 'rb') > f.seek(DATA_OFFSET) > self.__data = f.read(DATA_SIZE) > self.isDataLoaded = True > except: > self.isDataLoaded = False > finally: > f.close() > > Can someone tell me what's wrong with the code? Am I doing something > wrong? I'm somewhat new to python but this makes sense to me. > finally: block is executed even if there is an exception in which case f hasn't been defined. What you want is:
try: f = file(self.filename, 'rb') f.seek(DATA_OFFSET) self.__data = f.read(DATA_SIZE) self.isDataLoaded = True except: isDataLoaded=False else: f.close() -Larry -- http://mail.python.org/mailman/listinfo/python-list