From 106f9ea444ee9ed8246be128f232217b6c4977b8 Mon Sep 17 00:00:00 2001 From: Scott Maxwell Date: Tue, 19 Nov 2013 08:56:53 -0800 Subject: [PATCH] Use 'with' for opening most file and SFTPFIle objects --- demos/demo_sftp.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/demos/demo_sftp.py b/demos/demo_sftp.py index 9476f76..c04d6e1 100755 --- a/demos/demo_sftp.py +++ b/demos/demo_sftp.py @@ -104,7 +104,8 @@ try: print('created demo_sftp_folder/ on the server') # copy the README back here - data = sftp.open('demo_sftp_folder/README', 'r').read() + with sftp.open('demo_sftp_folder/README', 'r') as f: + data = f.read() with open('README_demo_sftp', 'w') as f: f.write(data) print('copied README back here')