Skip to content

Commit

Permalink
Create dir
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxuan-ji committed Mar 14, 2021
1 parent bdd9973 commit 5414bca
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pyserini/output_writer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os

from abc import ABC, abstractmethod
from enum import Enum, unique
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 5414bca

Please sign in to comment.