Skip to content

Commit

Permalink
Update start.py to fix the file class where an antipattern was used c…
Browse files Browse the repository at this point in the history
…ausing issues when handling the updates.txt file.

I have implemented the WITH class to ensure that the file is properly and safely opened and closed.
  • Loading branch information
genome21 committed Feb 4, 2016
1 parent 76ddeb1 commit 9a8e718
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions start.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import getpass
import datetime

morningstart = open('updates.txt', 'r')
morningstart.read()
linelist = morningstart.readline()
morningstart.close()
with open('updates.txt', 'r') as morningstart:
morningstart.read()
linelist = morningstart.readline()

operstamp = getpass.getuser()
timestamp = datetime.datetime.now().strftime('%Y%m%d-%H:%M:%S')
dailyupdates = open('updates.txt', 'a')

with open('updates.txt', 'a') as dailyupdates:
print('This is your last update: ')
print (linelist)
print('What are your updates?')
Expand All @@ -21,4 +22,3 @@
dailyupdates.write(typedupdates)
ender = "\nEOF-------------------------------------------EOF\n\n"
dailyupdates.write(ender)
dailyupdates.close()

0 comments on commit 9a8e718

Please sign in to comment.