This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: CSV-module. The example code don't work. Have to be: reader = csv.reader(csvfile, dialect=dialect)
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: SilentGhost, Vasyl Kolomiets, docs@python, georg.brandl
Priority: normal Keywords:

Created on 2016-01-14 21:50 by Vasyl Kolomiets, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
may_be-error_csv_exmpl.py Vasyl Kolomiets, 2016-01-14 23:20
from_to_proportions.csv Vasyl Kolomiets, 2016-01-14 23:20
may_be-good_csv_exmpl.py Vasyl Kolomiets, 2016-01-14 23:20
CSV-ex.png Vasyl Kolomiets, 2016-01-14 23:55
Messages (8)
msg258227 - (view) Author: Василь Коломієць (Vasyl Kolomiets) * Date: 2016-01-14 21:50
with open('example.csv') as csvfile:
    dialect = csv.Sniffer().sniff(csvfile.read(1024))
    csvfile.seek(0)
    reader = csv.reader(csvfile, dialect)
    # ... process CSV file contents here ...
--

have to be:
    ...
    reader = csv.reader(csvfile, dialect=dialect)
     # ... process CSV file contents here ...

It's here:
https://docs.python.org/3.4/library/csv.html
msg258229 - (view) Author: Василь Коломієць (Vasyl Kolomiets) * Date: 2016-01-14 21:54
Traceback (most recent call last):
  File "F:\Program Files (x86)\Pyton3_4\=Py\NovaPoshta\View#1-check-Trojan.py", line 11, in <module>
    for row in readed:
  File "F:\Program Files (x86)\Pyton3_4\lib\csv.py", line 118, in __next__
    d = dict(zip(self.fieldnames, row))
TypeError: zip argument #1 must support iteration
msg258234 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2016-01-14 22:18
Vasyl, this line in your code is causing the problem:

    for row in readed:

The error reasonably clear states that it's due to your `fieldnames' parameter being non-iterable. Again, this has nothing whatsoever to do with `dialect' argument and documentation of Sniffer. 

Please, do not open new issues about this. This is not a issue with csv library or its documentation. Try to use use stackoverflow or python-tutor list to get help on this.
https://mail.python.org/pipermail/tutor/
msg258240 - (view) Author: Василь Коломієць (Vasyl Kolomiets) * Date: 2016-01-14 22:36
Thanx a lot.
And sorry.
But with ..., dialect=dialect, .... the same code is working.
.
Ok. i'll try to understand.
With best wishes - VK.

С уважением,
Василий Коломиец
+38050 45 22 559

2016-01-15 0:18 GMT+02:00 SilentGhost <report@bugs.python.org>:

>
> SilentGhost added the comment:
>
> Vasyl, this line in your code is causing the problem:
>
>     for row in readed:
>
> The error reasonably clear states that it's due to your `fieldnames'
> parameter being non-iterable. Again, this has nothing whatsoever to do with
> `dialect' argument and documentation of Sniffer.
>
> Please, do not open new issues about this. This is not a issue with csv
> library or its documentation. Try to use use stackoverflow or python-tutor
> list to get help on this.
> https://mail.python.org/pipermail/tutor/
>
> ----------
> nosy: +SilentGhost
> resolution:  -> not a bug
> stage:  -> resolved
> status: open -> closed
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue26116>
> _______________________________________
>
msg258241 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2016-01-14 22:38
We'll need at least the two full examples (one not working, one working) to make a call here.
msg258249 - (view) Author: Василь Коломієць (Vasyl Kolomiets) * Date: 2016-01-14 23:20
I am very happy!
Thx for attention to my opinion.
Sorry for my english.

so - in attachment two codes and source csv-file.

With best wishes,
Vasyl Kolomiets.
+38050 45 22 559

2016-01-15 0:38 GMT+02:00 Georg Brandl <report@bugs.python.org>:

>
> Georg Brandl added the comment:
>
> We'll need at least the two full examples (one not working, one working)
> to make a call here.
>
> ----------
> nosy: +georg.brandl
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue26116>
> _______________________________________
>
msg258273 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2016-01-15 07:25
Thanks!  Now the reason is clear: You use csv.DictReader instead of csv.reader. csv.DictReader has a different argument list - for DictReader the second argument is `fieldnames`.
msg258278 - (view) Author: Василь Коломієць (Vasyl Kolomiets) * Date: 2016-01-15 08:41
))
Thanks!
Be happy!
History
Date User Action Args
2022-04-11 14:58:26adminsetgithub: 70304
2016-01-15 08:41:13Vasyl Kolomietssetmessages: + msg258278
2016-01-15 07:25:15georg.brandlsetmessages: + msg258273
2016-01-14 23:55:04Vasyl Kolomietssetfiles: + CSV-ex.png
2016-01-14 23:20:31Vasyl Kolomietssetfiles: + may_be-error_csv_exmpl.py, from_to_proportions.csv, may_be-good_csv_exmpl.py

messages: + msg258249
2016-01-14 22:38:04georg.brandlsetnosy: + georg.brandl
messages: + msg258241
2016-01-14 22:36:24Vasyl Kolomietssetmessages: + msg258240
title: CSV-module. The example code don't work. Have to be: reader = csv.reader(csvfile, dialect=dialect) -> CSV-module. The example code don't work. Have to be: reader = csv.reader(csvfile, dialect=dialect)
2016-01-14 22:18:30SilentGhostsetstatus: open -> closed

nosy: + SilentGhost
messages: + msg258234

resolution: not a bug
stage: resolved
2016-01-14 21:54:33Vasyl Kolomietssetmessages: + msg258229
2016-01-14 21:50:32Vasyl Kolomietscreate