mirror of
https://github.com/OpenVGLab/OmniLottie.git
synced 2026-09-17 07:36:27 +00:00
14 lines
285 B
Python
14 lines
285 B
Python
from contextlib import contextmanager
|
|
|
|
|
|
@contextmanager
|
|
def open_file(file_or_name, mode="w"):
|
|
if isinstance(file_or_name, str):
|
|
obj = open(file_or_name, mode)
|
|
try:
|
|
yield obj
|
|
finally:
|
|
obj.close()
|
|
else:
|
|
yield file_or_name
|