Skip to content

Commit

Permalink
Safe file handling, closes #18
Browse files Browse the repository at this point in the history
  • Loading branch information
nims11 authored and NicoHood committed Feb 4, 2016
1 parent bcde228 commit 15b3057
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions shuffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,8 @@ def remove_relatives(self, relative, filename):
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':
Expand Down Expand Up @@ -529,9 +528,8 @@ def populate(self):
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
Expand Down

0 comments on commit 15b3057

Please sign in to comment.