summaryrefslogtreecommitdiff
path: root/Lib/aifc.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-08-25 19:12:56 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2013-08-25 19:12:56 +0300
commitb33baf1c9f7b2d811ef53f48988aa5d8403bd884 (patch)
treef4dd25f4a8b3daf9dc4b0cab948b33af4730bb92 /Lib/aifc.py
parentcd0f74b1e09a50acc073aa57c1345968257a9056 (diff)
downloadcpython-git-b33baf1c9f7b2d811ef53f48988aa5d8403bd884.tar.gz
Issue #18817: Fix a resource warning in Lib/aifc.py demo.
Diffstat (limited to 'Lib/aifc.py')
-rw-r--r--Lib/aifc.py42
1 files changed, 23 insertions, 19 deletions
diff --git a/Lib/aifc.py b/Lib/aifc.py
index 29545a5fb8..3270047b11 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.")