我的文件是一直打开还是自动关闭?

问题描述 投票:0回答:1

我有这样一段代码,我想知道我的文件在执行后是保持打开还是自动关闭?

    features_dict = json.load(open(features_path))

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

python python-3.x
1个回答
2
投票

文件保持打开状态,你需要关闭它或者使用 with open 并且在超出范围后会自动关闭。

with open ('features_path','r') as features_path:
    #Do stuff
© www.soinside.com 2019 - 2024. All rights reserved.