[Python] will using list comprehension to read a file automagically call close()

Discussão em 'Python' iniciado por Stack, Setembro 25, 2024.

  1. Stack

    Stack Membro Participativo

    Does the following syntax close the file:

    lines = [line.strip() for line in open('/somefile/somewhere')]


    Bonus points if you can demonstrate how it does or does not...

    TIA!

    Continue reading...

Compartilhe esta Página