@@ -157,9 +157,8 @@ def save(self):
157157 state [name ][key ] = value
158158 else :
159159 state [name ] = attr
160- f = open (_get_project_file (self .path ), 'w' ) # should check if file exists?
161- json .dump (state , f , indent = 2 )
162- f .close ()
160+ with open (_get_project_file (self .path ), 'w' ) as f : # should check if file exists?
161+ json .dump (state , f , indent = 2 )
163162
164163 def info (self ):
165164 """Show some basic information about the project."""
@@ -393,9 +392,8 @@ def export(self):
393392 # copy the project data
394393 shutil .copy (".smt/project" , ".smt/project_export.json" )
395394 # export the record data
396- f = open (".smt/records_export.json" , 'w' )
397- f .write (self .record_store .export (self .name ))
398- f .close ()
395+ with open (".smt/records_export.json" , 'w' ) as f :
396+ f .write (self .record_store .export (self .name ))
399397
400398 def repeat (self , original_label , new_label = None ):
401399 if original_label == 'last' :
@@ -474,9 +472,8 @@ def remove_plugins(self, *plugins):
474472
475473
476474def _load_project_from_json (path ):
477- f = open (_get_project_file (path ), 'r' )
478- data = json .load (f )
479- f .close ()
475+ with open (_get_project_file (path ), 'r' ) as f :
476+ data = json .load (f )
480477 prj = Project .__new__ (Project )
481478 prj .path = path
482479 for key , value in data .items ():
@@ -502,9 +499,8 @@ def _load_project_from_json(path):
502499
503500def _load_project_from_pickle (path ):
504501 # earlier versions of Sumatra saved Projects using pickle
505- f = open (_get_project_file (path ), 'r' )
506- prj = pickle .load (f )
507- f .close ()
502+ with open (_get_project_file (path ), 'r' ) as f :
503+ prj = pickle .load (f )
508504 return prj
509505
510506
0 commit comments