def _open_for_write(filename):
dirname = os.path.dirname(filename)<EOL>pathlib.Path(dirname).mkdir(parents=True, exist_ok=True)<EOL>return io.open(filename, '<STR_LIT:w>')<EOL>
Opens filename for writing, creating the directories if needed.