diff options
author | Andrew McNamara <andrewm@object-craft.com.au> | 2005-01-12 11:17:16 (GMT) |
---|---|---|
committer | Andrew McNamara <andrewm@object-craft.com.au> | 2005-01-12 11:17:16 (GMT) |
commit | 7f2053eff3ec1ee9084a3a550ae363a804368322 (patch) | |
tree | 8ae5c4d637feab5886fca99be4486653ce4a3b7d /Modules/_csv.c | |
parent | 0f0599ddc1ad02f392fe0be58479f34c57a80c8d (diff) | |
download | cpython-7f2053eff3ec1ee9084a3a550ae363a804368322.zip cpython-7f2053eff3ec1ee9084a3a550ae363a804368322.tar.gz cpython-7f2053eff3ec1ee9084a3a550ae363a804368322.tar.bz2 |
Add counting of source iterator lines to the reader object - handy for
user error messages (otherwise difficult to do without instrumenting
the source).
Diffstat (limited to 'Modules/_csv.c')
-rw-r--r-- | Modules/_csv.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Modules/_csv.c b/Modules/_csv.c index 6941714..ce4c738 100644 --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -98,6 +98,7 @@ typedef struct { int field_len; /* length of current field */ int had_parse_error; /* did we have a parse error? */ int numeric_field; /* treat field as numeric */ + unsigned long line_num; /* Source-file line number */ } ReaderObj; staticforward PyTypeObject Reader_Type; @@ -734,6 +735,7 @@ parse_process_char(ReaderObj *self, char c) static struct PyMemberDef Reader_memberlist[] = { { "dialect", T_OBJECT, R_OFF(dialect), RO }, + { "line_num", T_ULONG, R_OFF(line_num), RO }, { NULL } }; @@ -753,6 +755,7 @@ Reader_iternext(ReaderObj *self) "newline inside string"); return NULL; } + ++self->line_num; if (self->had_parse_error) if (parse_reset(self) < 0) { @@ -924,6 +927,7 @@ csv_reader(PyObject *module, PyObject *args, PyObject *keyword_args) self->input_iter = NULL; self->field = NULL; self->field_size = 0; + self->line_num = 0; if (parse_reset(self) < 0) { Py_DECREF(self); |