Steven
Steven

Reputation: 15258

does my file stay open or closes automatically?

I have this piece of code :

    features_dict = json.load(open(features_path))

I want to know if my file stays open after the execution or if it closes automatically ?

Upvotes: 1

Views: 69

Answers (1)

user12867493
user12867493

Reputation:

The file stays open and you need to close it or use with open and it will close automatically after going out of scope:

with open ('features_path','r') as features_path:
    #Do stuff

Upvotes: 2

Related Questions