'return an opened file with the given mode.
If ensure is True, create parent directories if needed.'

def open(self, mode='r', ensure=False, encoding=None):

    if ensure:
        self.dirpath().ensure(dir=1)
    if encoding:
        return py.error.checked_call(io.open, self.strpath, mode, encoding=encoding)
    return py.error.checked_call(open, self.strpath, mode)
