2017-01-13 19:34:48 +01:00
|
|
|
import os
|
2017-02-09 22:12:30 +01:00
|
|
|
from contextlib import contextmanager
|
|
|
|
|
2017-01-13 19:34:48 +01:00
|
|
|
|
2017-02-09 22:12:30 +01:00
|
|
|
@contextmanager
|
|
|
|
def get_read_handle(path):
|
|
|
|
"""
|
|
|
|
Get os independent read handle for a file
|
|
|
|
"""
|
|
|
|
|
|
|
|
if os.name == "nt":
|
|
|
|
file_mode = 'rb'
|
|
|
|
else:
|
|
|
|
file_mode = 'r'
|
|
|
|
read_handle = open(path, file_mode)
|
|
|
|
yield read_handle
|
|
|
|
read_handle.close()
|