def _get_file_object(csvfile, encoding=None):
if isinstance(csvfile, str):
assert encoding, 'encoding required for file path'
return open(csvfile, 'rt', encoding=encoding, newline='') # <- EXIT!
if hasattr(csvfile, 'mode'):
assert 'b' not in csvfile.mode, "File must be open in text mode ('rt')."
elif issubclass(csvfile.__class__, io.IOBase):
assert issubclass(csvfile.__class__, io.TextIOBase), ("Stream object must inherit "
"from io.TextIOBase.")
return csvfile
评论列表
文章目录