[Python] ValueError : I/O operation on closed file

Discussão em 'Python' iniciado por Stack, Agosto 13, 2025.

  1. Stack

    Stack Membro Participativo

    import csv

    with open('v.csv', 'w') as csvfile:
    cwriter = csv.writer(csvfile, delimiter=' ', quotechar='|', quoting=csv.QUOTE_MINIMAL)

    for w, c in p.items():
    cwriter.writerow(w + c)


    Here, p is a dictionary, w and c both are strings.

    When I try to write to the file it reports the error:

    ValueError: I/O operation on closed file.

    Continue reading...

Compartilhe esta Página