summaryrefslogtreecommitdiffstats
path: root/Lib/aifc.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-08-25 16:16:01 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-08-25 16:16:01 (GMT)
commit58b3ebfab92d4241e65fbb0f34c84746fcbe347b (patch)
tree3ef075b81e593ff0bdb8fa3de19ddd9cab8660af /Lib/aifc.py
parent0cb8e5131d0797d3bdb1494de842e98798174cf2 (diff)
parentb33baf1c9f7b2d811ef53f48988aa5d8403bd884 (diff)
downloadcpython-58b3ebfab92d4241e65fbb0f34c84746fcbe347b.zip
cpython-58b3ebfab92d4241e65fbb0f34c84746fcbe347b.tar.gz
cpython-58b3ebfab92d4241e65fbb0f34c84746fcbe347b.tar.bz2
Issue #18817: Fix a resource warning in Lib/aifc.py demo. Patch by
Vajrasky Kok.
Diffstat (limited to 'Lib/aifc.py')
-rw-r--r--Lib/aifc.py40
1 files changed, 19 insertions, 21 deletions
diff --git a/Lib/aifc.py b/Lib/aifc.py
index c02c485..b087754 100644
--- a/Lib/aifc.py
+++ b/Lib/aifc.py
@@ -889,24 +889,22 @@ if __name__ == '__main__':
if not sys.argv[1:]:
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()
- f.close()
- print("Done.")
+ with open(fn, 'r') as f:
+ 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)
+ with open(gn, 'w') as g:
+ g.setparams(f.getparams())
+ while 1:
+ data = f.readframes(1024)
+ if not data:
+ break
+ g.writeframes(data)
+ print("Done.")