try except inside a with open

Ganesh Pal ganesh1pal at
Sat Jul 21 05:43:26 EDT 2018

> (1) Since this function always returns True (if it returns at all), what
> is the point? There's no point checking the return result, since it's
> always true, so why bother returning anything?

If  I don't return anything from a function it returns None.   But would it
be better if for the  function  i.e modify_various_line(f) to  atleast catch
or handle exceptions and log it for debugging purpose


def modify_various_line(f):
    """ Try modifiying various line """
        f.write('0123456789abcdef')     # Go to the 6th byte in the file
        print, 2) # Go to the 3rd byte before the end
    except IOError as e:
       logging.error("Error: got %s" , % (str(e)))

More information about the Python-list mailing list