Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
d9b9d680
Commit
d9b9d680
authored
Mar 21, 2008
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #2432: give DictReader the dialect and line_num attributes
advertised in the docs. (backport from r61712)
parent
4af861cb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
10 deletions
+18
-10
Lib/csv.py
Lib/csv.py
+3
-0
Lib/test/test_csv.py
Lib/test/test_csv.py
+12
-10
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/csv.py
View file @
d9b9d680
...
...
@@ -75,6 +75,8 @@ class DictReader:
self
.
restkey
=
restkey
# key to catch long rows
self
.
restval
=
restval
# default value for short rows
self
.
reader
=
reader
(
f
,
dialect
,
*
args
,
**
kwds
)
self
.
dialect
=
dialect
self
.
line_num
=
0
def
__iter__
(
self
):
return
self
...
...
@@ -84,6 +86,7 @@ class DictReader:
if
self
.
fieldnames
is
None
:
self
.
fieldnames
=
row
row
=
self
.
reader
.
next
()
self
.
line_num
=
self
.
reader
.
line_num
# unlike the basic reader, we prefer not to return blanks,
# because we will typically wind up with a dict full of None
...
...
Lib/test/test_csv.py
View file @
d9b9d680
...
...
@@ -269,16 +269,18 @@ class Test_Csv(unittest.TestCase):
csv
.
field_size_limit
(
limit
)
def
test_read_linenum
(
self
):
r
=
csv
.
reader
([
'line,1'
,
'line,2'
,
'line,3'
])
self
.
assertEqual
(
r
.
line_num
,
0
)
r
.
next
()
self
.
assertEqual
(
r
.
line_num
,
1
)
r
.
next
()
self
.
assertEqual
(
r
.
line_num
,
2
)
r
.
next
()
self
.
assertEqual
(
r
.
line_num
,
3
)
self
.
assertRaises
(
StopIteration
,
r
.
next
)
self
.
assertEqual
(
r
.
line_num
,
3
)
for
r
in
(
csv
.
reader
([
'line,1'
,
'line,2'
,
'line,3'
]),
csv
.
DictReader
([
'line,1'
,
'line,2'
,
'line,3'
],
fieldnames
=
[
'a'
,
'b'
,
'c'
])):
self
.
assertEqual
(
r
.
line_num
,
0
)
r
.
next
()
self
.
assertEqual
(
r
.
line_num
,
1
)
r
.
next
()
self
.
assertEqual
(
r
.
line_num
,
2
)
r
.
next
()
self
.
assertEqual
(
r
.
line_num
,
3
)
self
.
assertRaises
(
StopIteration
,
r
.
next
)
self
.
assertEqual
(
r
.
line_num
,
3
)
class
TestDialectRegistry
(
unittest
.
TestCase
):
def
test_registry_badargs
(
self
):
...
...
Misc/NEWS
View file @
d9b9d680
...
...
@@ -20,6 +20,9 @@ Core and builtins
Library
-------
- Issue #2432: give DictReader the dialect and line_num attributes
advertised in the docs.
- Issue #1747858: Fix chown to work with large uid'
s
and
gid
's on 64-bit
platforms.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment