diff options
Diffstat (limited to 'yaksh/file_utils.py')
-rw-r--r-- | yaksh/file_utils.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/yaksh/file_utils.py b/yaksh/file_utils.py index f41c531..b178eeb 100644 --- a/yaksh/file_utils.py +++ b/yaksh/file_utils.py @@ -2,7 +2,7 @@ import shutil import os import zipfile import tempfile - +import csv def copy_files(file_paths): """ Copy Files to current directory, takes @@ -50,3 +50,19 @@ def extract_files(zip_file, path=None): zip_file.close() return zfiles, extract_path + +def is_csv(document): + ''' Check if document is csv with ',' as the delimiter''' + try: + try: + content = document.read(1024).decode('utf-8') + except AttributeError: + document.seek(0) + content = document.read(1024) + sniffer = csv.Sniffer() + dialect = sniffer.sniff(content, delimiters=',') + document.seek(0) + except (csv.Error, UnicodeDecodeError): + return False, None + return True, dialect + |