csv2lyx: use universal newlines when reading CSVs

Patch from Dustin J. Mitchell.
This commit is contained in:
Scott Kostyshak 2014-02-16 00:07:43 -05:00
parent 2ec8880e47
commit b36b59d06a
2 changed files with 7 additions and 5 deletions

View File

@ -165,21 +165,21 @@ if options.column_sep == 't':
# when no special column separator is given, try to detect it:
if options.column_sep and dialect :
reader = csv.reader(open(infile, "rb"), dialect = dialect, delimiter = options.column_sep)
reader = csv.reader(open(infile, "rU"), dialect = dialect, delimiter = options.column_sep)
else:
guesser = csv.Sniffer()
input_file = "".join(open(infile,'rb').readlines())
input_file = "".join(open(infile,'rU').readlines())
try:
dialect = guesser.sniff(input_file)
reader = csv.reader(open(infile, "rb"), dialect = dialect)
reader = csv.reader(open(infile, "rU"), dialect = dialect)
except:
# older versions (python < 2.5) of csv have problems (bugs)
# that is why we try harder to get a result, this should work on most cases
# as it assumes that the separator is a comma (the c in csv :-) )
try:
reader = csv.reader(open(infile, "rb"), dialect = dialect, delimiter = ',')
reader = csv.reader(open(infile, "rU"), dialect = dialect, delimiter = ',')
except:
reader = csv.reader(open(infile, "rb"), delimiter = ',')
reader = csv.reader(open(infile, "rU"), delimiter = ',')
# read input
num_cols = 1 # max columns

View File

@ -61,6 +61,8 @@ What's new
- Support (black) card suites in text mode (bug 8971).
- Use universal newlines when reading CSVs
* USER INTERFACE