📜  contextlib 关闭 python 文件 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:20.630000             🧑  作者: Mango

代码示例1
from contextlib import closing
import csv
# STEP 1: 
# Baca file "harga_rumah.txt"
url = "url"
data = []
with closing(requests.get(url, stream=True)) as r:
    f = (line.decode('utf-8') for line in r.iter_lines())
    data = [row for row in csv.reader(f)]