diff options
author | Scott Maxwell <scott@codecobblers.com> | 2013-11-02 20:18:18 -0700 |
---|---|---|
committer | Scott Maxwell <scott@codecobblers.com> | 2013-11-02 20:19:04 -0700 |
commit | 7444a999931cddc1e61bb35270468aa45da2687e (patch) | |
tree | 1ac60cc2d3a949285e3a4917c05c19a6d03c775d /demos/demo_sftp.py | |
parent | 45e65b6e1eb47944a26e4349d41998844c155df5 (diff) |
Fix some deprecation and resource warnings
Diffstat (limited to 'demos/demo_sftp.py')
-rwxr-xr-x | demos/demo_sftp.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/demos/demo_sftp.py b/demos/demo_sftp.py index 2dba1722..d7f28084 100755 --- a/demos/demo_sftp.py +++ b/demos/demo_sftp.py @@ -20,6 +20,8 @@ # based on code provided by raymond mosteller (thanks!) +from __future__ import with_statement + import base64 import getpass import os @@ -95,13 +97,15 @@ try: except IOError: print('(assuming demo_sftp_folder/ already exists)') sftp.open('demo_sftp_folder/README', 'w').write('This was created by demo_sftp.py.\n') - data = open('demo_sftp.py', 'r').read() + with open('demo_sftp.py', 'r') as f: + data = f.read() sftp.open('demo_sftp_folder/demo_sftp.py', 'w').write(data) print('created demo_sftp_folder/ on the server') # copy the README back here data = sftp.open('demo_sftp_folder/README', 'r').read() - open('README_demo_sftp', 'w').write(data) + with open('README_demo_sftp', 'w') as f: + f.write(data) print('copied README back here') # BETTER: use the get() and put() methods |