1. Guillermo Szeliga
  2. longtang

Commits

Guillermo Szeliga  committed fb99d58

Changed file management to use with statement

  • Participants
  • Parent commits 8d7982e
  • Branches master

Comments (0)

Files changed (1)

File longtang/actors/outbound/amazon/albumcoverart.py

View file
 
             #print(etree.tostring(item, pretty_print=True))
 
-            fh = urllib2.urlopen(url)
-            outh = open(target_local_file, 'wb')
+            with open(target_local_file, 'wb') as target:
 
-            while True:
-                buffer = fh.read(block_sz)
-                
-                if not buffer:
-                    break
+                fh = urllib2.urlopen(url)
 
-                outh.write(buffer)
+                while True:
+                    buffer = fh.read(block_sz)
+                    
+                    if not buffer:
+                        break
 
-            fh.close()
-            outh.close()
+                    target.write(buffer)
+
+                fh.close()
 
             break