Raise Error Could Not Determine Delimiter
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings python csv could not determine delimiter and policies of this site About Us Learn more about Stack Overflow python csv sniffer the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Find delimiter in txt to convert to csv using Python up vote 5 down vote favorite I have to convert some txt files to csv (and make some operation during the conversion). I use csv.Sniffer() class to detect wich delimiter is used in the txt This code with open(filename_input, 'r') as f1, open(filename_output, 'wb') as f2: dialect = csv.Sniffer().sniff(f1.read(1024)) #### detect delimiters f1.seek(0) r=csv.reader(f1, delimiter=dialect ) writer = csv.writer(f2,delimiter=';') return: Error: Could not determine delimiter This work with open(filename_input, 'r') as f1, open(filename_output, 'wb') as f2: #dialect = csv.Sniffer().sniff(f1.read(1024)) #### detect delimiters #f1.seek(0) r=csv.reader(f1, delimiter='\t' ) writer = csv.writer(f2,delimiter=';') or with open(filename_input, 'r') as f1, open(filename_output, 'wb') as f2: #dialect = csv.Sniffer().sniff(f1.read(1024)) #### detect delimiters #f1.seek(0) r=csv.reader(f1, dialect="excel-tab") writer = csv.writer(f2,delimiter=';') this is a txt row example (10 records delimited by Tab) 166 14908941 sa_s NOVA i 7.05 DEa 7.17 Ncava - Deo mo 7161 4,97 why csv.Sniffer() class doesn't work? The bug was read only 1024 byte to parse the entire txt(maybe this is not enough to detect the delimiter). Now this code works without no other edit: with open(filename_input, 'r') as f1, open(filename_output, 'wb') as f2: dialect = csv.Sniffer().sniff(f1.read()) #### error with dialect = csv.Sniffer().sniff(f1.read(1024)) f1.seek(0) r=csv.reader(f1, delimiter=dialect ) writer = csv.writer(f2,delimiter=';') python csv share|improve this question edited Jan 29 '14 at 9:17 asked Jan 28 '14 at 14:16 franco_b 13614 And what is dialect as returned by csv.excel_tab().
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Reading a file with “latin small letter thorn” as delimiter http://stackoverflow.com/questions/21407993/find-delimiter-in-txt-to-convert-to-csv-using-python in python up vote 0 down vote favorite I am trying to read a file that has the "latin small letter thorn" http://www.fileformat.info/info/unicode/char/fe/index.htm as a delimiter. I am trying to use the csv file https://docs.python.org/3.0/library/csv.html API for the same. I tried various ways to represent the delimiter in the source code, but it always errors out: dialect = csv.Sniffer().sniff(f.readline(), delimiters='\xc3\xbe') print dialect.delimiter Error: File "/usr/lib64/python2.6/csv.py", line 180, in sniff http://stackoverflow.com/questions/22927551/reading-a-file-with-latin-small-letter-thorn-as-delimiter-in-python raise Error, "Could not determine delimiter" _csv.Error: Could not determine delimiter How do I represent such characters as delimiters in the csv API in python? Thanks in advance! python csv share|improve this question asked Apr 8 '14 at 4:27 user3509350 11 3 Use Python 3 if you can -- it has much better unicode support. Then you can just copy the "small thorn" into your source code and all will be well. In Python 2.6, you need to make sure you set ~*~coding: utf-8~*~ at the top of the file and use u'' unicode strings and such. Also, mind your Python versions. You are linking to the Python 3 docs but your error is Python 2.6! –Two-Bit Alchemist Apr 8 '14 at 4:29 Unfortunately I cant use python 3 :(. I tried setting the encoding via # -- coding: utf-8 -- and entering the delimiters as delimiters=u'\u00FE', but that doesnt solve the problem either :( –user3509350 Apr 8 '14 at 4:36 1 It seems highly unlikely to use a Unicode multibyte alphabetic as a CSV delimiter. Are you sure the file is UTF-8? –tripleee Apr 8 '14 at 4:45 Your question reminded me of this graphic: media-cache-c
Sign in Pricing Blog Support Search GitHub This repository Watch 12 Star 131 Fork 33 anirudhjoshi/lastpass2keepass https://github.com/anirudhjoshi/lastpass2keepass/issues/2 Code Issues 0 Pull requests 2 Projects 0 Pulse Graphs New issue Could not determine delimiter #2 Closed apropos opened this Issue Nov 3, 2010 · http://code.activestate.com/lists/python-list/623327/ 2 comments Labels None yet Milestone No milestone Assignees No one assigned 2 participants apropos commented Nov 3, 2010 LastPass CSV export from could not Firefox addon running with Python 2.6.4 outputs the following error. I've verified that the CSV uses , (comma) for delimiter and I've removed all the secure notes and form fills so that there are no single column lines. Traceback (most recent call last): File "lastpass2keepass.py", line 48, in dialect = csv.Sniffer().sniff(f.read(1024),delimiters=',') File "/usr/lib/python2.6/csv.py", could not determine line 180, in sniff raise Error, "Could not determine delimiter" _csv.Error: Could not determine delimiter Owner anirudhjoshi commented Nov 3, 2010 I've changed the script so that just parses. dialect = csv.Sniffer().sniff(f.read(1024),delimiters=',') to reader = csv.reader(f, delimiter=',', quotechar='\n') Redownload and try again. If it still doesn't work you can just use the firefox password manager: http://forums.lastpass.com/viewtopic.php?f=7&t=1409&sid=15a9bb34e48c7822ad4771cb28e50b8e&start=10. Or this ruby script: https://gist.github.com/436947 apropos commented Nov 4, 2010 Perfect, thanks! I had to use this because KeeFox plugin doesn't work with Firefox running in Ubuntu. This issue was closed. Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment Contact GitHub API Training Shop Blog About © 2016 GitHub, Inc. Terms Privacy Security Status Help You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Perl Lists Python Lists PHP Lists Ruby Lists Tcl Lists ActiveState Lists Lists » python-list Re: Odd csv column-name truncation with only one column From: Peter Otten <__pe...@web.de> Thu, 19 Jul 2012 13:49:53 +0200 Tim Chase wrote: > t...@laptop:~/tmp$ python> Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)> [GCC 4.4.5] on linux2> Type "help", "copyright", "credits" or "license" for more information.>>>> import csv>>>> from cStringIO import StringIO>>>> s = StringIO('Email\n...@example.com\n...@example.org\n')>>>> s.seek(0)>>>> d = csv.Sniffer().sniff(s.read())>>>> s.seek(0)>>>> r = csv.DictReader(s, dialect=d)>>>> r.fieldnames> ['Emai', '']> > I get the same results using Python 3.1.3 (also readily available on> Debian Stable), as well as working directly on a file rather than a> StringIO.> > Any reason I'm getting ['Emai', ''] (note the missing ell) instead> of ['Email'] as my resulting fieldnames? Did I miss something in> the docs? Judging from >>> import csv>>> sniffer = csv.Sniffer()>>> sniffer.sniff("abc").delimiter 'c' >>> sniffer.sniff("abc\naba").delimiter 'b' >>> sniffer.sniff("abc\naba\nxyz").delimiter Traceback (most recent call last): File "