Skip to content

Commit

Permalink
Autodetect delimiter in CSV files, closes turicas#80
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanferri committed Oct 14, 2015
1 parent 84107e9 commit ce6fc69
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

**Released on: (under development)**

- Autodetect delimiter in CSV files
- Fix StringIO import for Python 3
- Fix error on import of older versions of urllib3
- Export to TXT also support an already opened file
Expand Down
8 changes: 7 additions & 1 deletion rows/plugins/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@
from rows.plugins.utils import create_table, get_filename_and_fobj, serialize


def import_from_csv(filename_or_fobj, encoding='utf-8', delimiter=',',
def import_from_csv(filename_or_fobj, encoding='utf-8', delimiter=None,
quotechar='"', *args, **kwargs):
'Import data from a CSV file'

filename, fobj = get_filename_and_fobj(filename_or_fobj)

if delimiter is None:
dialect = unicodecsv.Sniffer().sniff(fobj.read())
delimiter = dialect.delimiter
fobj.seek(0)

kwargs['encoding'] = encoding
csv_reader = unicodecsv.reader(fobj, encoding=encoding,
delimiter=str(delimiter),
Expand Down

0 comments on commit ce6fc69

Please sign in to comment.