我的文件会保持打开或自动关闭状态吗?

时间:2020-05-12 13:16:22

标签: python python-3.x

我有这段代码:

    features_dict = json.load(open(features_path))

我想知道我的文件在执行后保持打开状态还是自动关闭?

1 个答案:

答案 0 :(得分:2)

文件保持打开状态,您需要将其关闭或使用with open,超出范围后它将自动关闭:

with open ('features_path','r') as features_path:
    #Do stuff
相关问题