Use 'with' for opening most file and SFTPFIle objects

This commit is contained in:
Scott Maxwell 2013-11-19 08:56:53 -08:00
parent 2da5f1fb45
commit 106f9ea444
1 changed files with 2 additions and 1 deletions

View File

@ -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')