Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d5e9aa6

Browse filesBrowse files
authored
gh-118761: Improve import time for csv (#128858)
This reduces the import time of the `csv` module by up to five times, by importing `re` on demand. In particular, the `re` module is no more implicitly exposed as `csv.re`.
1 parent d3adf02 commit d5e9aa6
Copy full SHA for d5e9aa6

File tree

2 files changed

+4
-1
lines changed
Filter options

2 files changed

+4
-1
lines changed

‎Lib/csv.py

Copy file name to clipboardExpand all lines: Lib/csv.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ class excel:
6363
written as two quotes
6464
"""
6565

66-
import re
6766
import types
6867
from _csv import Error, writer, reader, register_dialect, \
6968
unregister_dialect, get_dialect, list_dialects, \
@@ -281,6 +280,7 @@ def _guess_quote_and_delimiter(self, data, delimiters):
281280
If there is no quotechar the delimiter can't be determined
282281
this way.
283282
"""
283+
import re
284284

285285
matches = []
286286
for restr in (r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)', # ,".*?",
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Reduce the import time of :mod:`csv` by up to five times, by importing
2+
:mod:`re` on demand. In particular, ``re`` is no more implicitly exposed
3+
as ``csv.re``. Patch by Bénédikt Tran.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.