From 5414bca90953a72a903d860beff887e66701eedc Mon Sep 17 00:00:00 2001 From: Yuxuan Ji Date: Sun, 14 Mar 2021 18:05:27 -0400 Subject: [PATCH] Create dir --- pyserini/output_writer.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyserini/output_writer.py b/pyserini/output_writer.py index 09b37e556..c961ad55e 100644 --- a/pyserini/output_writer.py +++ b/pyserini/output_writer.py @@ -1,4 +1,5 @@ import json +import os from abc import ABC, abstractmethod from enum import Enum, unique @@ -30,6 +31,9 @@ def __init__(self, file_path: str, mode: str = 'w', self.file = None def __enter__(self): + dirname = os.path.dirname(self.file_path) + if dirname: + os.makedirs(dirname, exist_ok=True) self.file = open(self.file_path, self.mode) return self