[Python] Read All Lines in Text File by Loop (with … as …:)

Read All Lines in Text File by Loop

with open(...) as file:
  for line in file:
    ...

The “with” Statement 

Invoke __enter__() and __exit__() methods
on entry to and exit from the body of the with statement.

用途

自動關閉檔案

Multiple Variables in a “with” Statement

with EXPR_1 as VAR_1[, EXPR_2 as VAR_2, ...]:

Last Updated on 2023/08/16 by A1go

目錄
Bitnami