diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-08-25 16:12:56 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-08-25 16:12:56 (GMT) |
commit | b33baf1c9f7b2d811ef53f48988aa5d8403bd884 (patch) | |
tree | f4dd25f4a8b3daf9dc4b0cab948b33af4730bb92 /Lib | |
parent | cd0f74b1e09a50acc073aa57c1345968257a9056 (diff) | |
download | cpython-b33baf1c9f7b2d811ef53f48988aa5d8403bd884.zip cpython-b33baf1c9f7b2d811ef53f48988aa5d8403bd884.tar.gz cpython-b33baf1c9f7b2d811ef53f48988aa5d8403bd884.tar.bz2 |
Issue #18817: Fix a resource warning in Lib/aifc.py demo.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/aifc.py | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/Lib/aifc.py b/Lib/aifc.py index 29545a5..3270047 100644 --- a/Lib/aifc.py +++ b/Lib/aifc.py @@ -873,23 +873,27 @@ if __name__ == '__main__': sys.argv.append('/usr/demos/data/audio/bach.aiff') fn = sys.argv[1] f = open(fn, 'r') - print("Reading", fn) - print("nchannels =", f.getnchannels()) - print("nframes =", f.getnframes()) - print("sampwidth =", f.getsampwidth()) - print("framerate =", f.getframerate()) - print("comptype =", f.getcomptype()) - print("compname =", f.getcompname()) - if sys.argv[2:]: - gn = sys.argv[2] - print("Writing", gn) - g = open(gn, 'w') - g.setparams(f.getparams()) - while 1: - data = f.readframes(1024) - if not data: - break - g.writeframes(data) - g.close() + try: + print("Reading", fn) + print("nchannels =", f.getnchannels()) + print("nframes =", f.getnframes()) + print("sampwidth =", f.getsampwidth()) + print("framerate =", f.getframerate()) + print("comptype =", f.getcomptype()) + print("compname =", f.getcompname()) + if sys.argv[2:]: + gn = sys.argv[2] + print("Writing", gn) + g = open(gn, 'w') + try: + g.setparams(f.getparams()) + while 1: + data = f.readframes(1024) + if not data: + break + g.writeframes(data) + finally: + g.close() + print("Done.") + finally: f.close() - print("Done.") |