[pyar] csvreader no acepta list objects

Luis Andraschnik luis.andraschnik en gmail.com
Mar Jun 12 16:30:12 -03 2018


Hola gente

Según la doc de Python 3.6 :

csv.reader(*csvfile*, *dialect='excel'*, ***fmtparams*)

Return a reader object which will iterate over lines in the given *csvfile*.
*csvfile* can be any object which supports the iterator
<https://docs.python.org/3/glossary.html#term-iterator> protocol and
returns a string each time its __next__() method is called — file objects
<https://docs.python.org/3/glossary.html#term-file-object> and ---->>****list
objects**** <<-------are both suitable
¿Porqué esto no funciona?

import csv
csv_list = [['Spam', 'Spam', 'Spam', 'Spam', 'Spam'], ['Baked Beans',
'Spam', 'Lovely Spam', 'Wonderful Spam']]
with open(csv_list) as csvfile:
    spamreader = csv.reader(csvfile, delimiter=',', quotechar="'")


Traceback (most recent call last):
  File "prueba.py", line 3, in <module>
    with open(csv_list) as csvfile:
TypeError: invalid file: [['Spam', 'Spam', 'Spam', 'Spam', 'Spam'], ['Baked
Beans', 'Spam', 'Lovely Spam', 'Wonderful Spam']]
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20180612/f562b75a/attachment.html>


Más información sobre la lista de distribución pyar