diff --git a/shuffle.py b/shuffle.py index 1caca0f..20e73f4 100755 --- a/shuffle.py +++ b/shuffle.py @@ -420,9 +420,8 @@ class Playlist(Record): return fullPath def populate(self, filename): - f = open(filename, "rb") - data = f.readlines() - f.close() + with open(filename, 'rb') as f: + data = f.readlines() extension = os.path.splitext(filename)[1].lower() if extension == '.pls': @@ -505,9 +504,8 @@ class Shuffler(object): self.lists.append(os.path.abspath(os.path.join(dirpath, filename))) def write_database(self): - f = open(os.path.join(self.base, "iPod_Control", "iTunes", "iTunesSD"), "wb") - f.write(self.tunessd.construct()) - f.close() + with open(os.path.join(self.base, "iPod_Control", "iTunes", "iTunesSD"), "wb") as f: + f.write(self.tunessd.construct()) # # Read all files from the directory