Make dirs for list_to_file (#235)

Signed-off-by: lizz <lizz@sensetime.com>
This commit is contained in:
lizz 2021-05-25 10:23:24 +08:00 committed by GitHub
parent b10b6408ef
commit 1e527e77be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,8 @@
import os
import mmcv
def list_to_file(filename, lines):
"""Write a list of strings to a text file.
@ -5,6 +10,7 @@ def list_to_file(filename, lines):
filename (str): The output filename. It will be created/overwritten.
lines (list(str)): Data to be written.
"""
mmcv.mkdir_or_exist(os.path.dirname(filename))
with open(filename, 'w', encoding='utf-8') as fw:
for line in lines:
fw.write(f'{line}\n')