From 1b667b4bfc00b79b84bb3801f7a22ce579de166d Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Tue, 30 Aug 2016 12:35:50 -0700 Subject: Issue #27842: The csv.DictReader now returns rows of type OrderedDict. --- Lib/csv.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Lib/csv.py') diff --git a/Lib/csv.py b/Lib/csv.py index 90461dbe1e..2e2303a28e 100644 --- a/Lib/csv.py +++ b/Lib/csv.py @@ -11,6 +11,7 @@ from _csv import Error, __version__, writer, reader, register_dialect, \ __doc__ from _csv import Dialect as _Dialect +from collections import OrderedDict from io import StringIO __all__ = ["QUOTE_MINIMAL", "QUOTE_ALL", "QUOTE_NONNUMERIC", "QUOTE_NONE", @@ -116,7 +117,7 @@ class DictReader: # values while row == []: row = next(self.reader) - d = dict(zip(self.fieldnames, row)) + d = OrderedDict(zip(self.fieldnames, row)) lf = len(self.fieldnames) lr = len(row) if lf < lr: -- cgit v1.2.1 From 03c8a473999b08710ae3661724cf1bf1d76bc555 Mon Sep 17 00:00:00 2001 From: R David Murray Date: Thu, 8 Sep 2016 13:59:53 -0400 Subject: #27364: fix "incorrect" uses of escape character in the stdlib. And most of the tools. Patch by Emanual Barry, reviewed by me, Serhiy Storchaka, and Martin Panter. --- Lib/csv.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Lib/csv.py') diff --git a/Lib/csv.py b/Lib/csv.py index 2e2303a28e..0481ea5586 100644 --- a/Lib/csv.py +++ b/Lib/csv.py @@ -215,10 +215,10 @@ class Sniffer: """ matches = [] - for restr in ('(?P[^\w\n"\'])(?P ?)(?P["\']).*?(?P=quote)(?P=delim)', # ,".*?", - '(?:^|\n)(?P["\']).*?(?P=quote)(?P[^\w\n"\'])(?P ?)', # ".*?", - '(?P>[^\w\n"\'])(?P ?)(?P["\']).*?(?P=quote)(?:$|\n)', # ,".*?" - '(?:^|\n)(?P["\']).*?(?P=quote)(?:$|\n)'): # ".*?" (no delim, no space) + for restr in (r'(?P[^\w\n"\'])(?P ?)(?P["\']).*?(?P=quote)(?P=delim)', # ,".*?", + r'(?:^|\n)(?P["\']).*?(?P=quote)(?P[^\w\n"\'])(?P ?)', # ".*?", + r'(?P>[^\w\n"\'])(?P ?)(?P["\']).*?(?P=quote)(?:$|\n)', # ,".*?" + r'(?:^|\n)(?P["\']).*?(?P=quote)(?:$|\n)'): # ".*?" (no delim, no space) regexp = re.compile(restr, re.DOTALL | re.MULTILINE) matches = regexp.findall(data) if matches: -- cgit v1.2.1 From 1c5a7b9be54055018447d61a270b7c3ac4850b19 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Fri, 21 Oct 2016 19:47:57 +0900 Subject: Issue #18219: Optimize csv.DictWriter for large number of columns. Patch by Mariatta Wijaya. --- Lib/csv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib/csv.py') diff --git a/Lib/csv.py b/Lib/csv.py index 0481ea5586..0349e0bd11 100644 --- a/Lib/csv.py +++ b/Lib/csv.py @@ -145,7 +145,7 @@ class DictWriter: def _dict_to_list(self, rowdict): if self.extrasaction == "raise": - wrong_fields = [k for k in rowdict if k not in self.fieldnames] + wrong_fields = rowdict.keys() - self.fieldnames if wrong_fields: raise ValueError("dict contains fields not in fieldnames: " + ", ".join([repr(x) for x in wrong_fields])) -- cgit v1.2.1