ich möchte einen csv-Writer als Generator benutzen:
Code: Alles auswählen
def generate_csv(entries):
for row in entries:
yield convert_one_row_to_csv(row, delimiter=";")
Code: Alles auswählen
def generate_csv(entries):
for row in entries:
yield convert_one_row_to_csv(row, delimiter=";")
https://docs.python.org/3/library/csv.html#csv.writer hat geschrieben:csvfile can be any object with a write() method.
Code: Alles auswählen
class LineWriter:
def write(self, s):
return s
def generate_csv(entries):
writer = csv.writer(LineWriter(), delimiter=";")
for row in entries:
yield writer.writerow(row)
So verquer ab ich nicht gedacht.csvwriter.writerow(row):
Write the row parameter to the writer’s file object, formatted according to the current dialect. Return the return value of the call to the write method of the underlying file object.