From 9a8e718420f2d537cb4705dc192beb8cb2099f95 Mon Sep 17 00:00:00 2001 From: Robert Wilkins III Date: Thu, 4 Feb 2016 04:55:17 -0600 Subject: [PATCH 1/3] Update start.py to fix the file class where an antipattern was used causing 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. --- start.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/start.py b/start.py index e84a360..afb70de 100644 --- a/start.py +++ b/start.py @@ -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?') @@ -21,4 +22,3 @@ dailyupdates.write(typedupdates) ender = "\nEOF-------------------------------------------EOF\n\n" dailyupdates.write(ender) -dailyupdates.close() From 40e651acc5a143d8cec0e215555360cfe71b2f6b Mon Sep 17 00:00:00 2001 From: Robert Wilkins III Date: Thu, 4 Feb 2016 05:14:23 -0600 Subject: [PATCH 2/3] Update start.py to fix issue in the WITH statements --- start.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/start.py b/start.py index afb70de..8efacd3 100644 --- a/start.py +++ b/start.py @@ -4,21 +4,20 @@ 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') + operstamp = getpass.getuser() + timestamp = datetime.datetime.now().strftime('%Y%m%d-%H:%M:%S') with open('updates.txt', 'a') as dailyupdates: -print('This is your last update: ') -print (linelist) -print('What are your updates?') -typedupdates = input() -nline = "\n" -iline = " -- " -dailyupdates.write(operstamp) -dailyupdates.write(iline) -dailyupdates.write(timestamp) -dailyupdates.write(nline) -dailyupdates.write(typedupdates) -ender = "\nEOF-------------------------------------------EOF\n\n" -dailyupdates.write(ender) + print('This is your last update: ') + print (linelist) + print('What are your updates?') + typedupdates = input() + nline = "\n" + iline = " -- " + dailyupdates.write(operstamp) + dailyupdates.write(iline) + dailyupdates.write(timestamp) + dailyupdates.write(nline) + dailyupdates.write(typedupdates) + ender = "\nEOF-------------------------------------------EOF\n\n" + dailyupdates.write(ender) From c425acb33f98809612ef565fab376e564cf37c4f Mon Sep 17 00:00:00 2001 From: Robert Wilkins III Date: Thu, 4 Feb 2016 05:22:22 -0600 Subject: [PATCH 3/3] Update start.py to limit indents to four spaces instead of five --- start.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/start.py b/start.py index 8efacd3..b459bf6 100644 --- a/start.py +++ b/start.py @@ -2,22 +2,22 @@ import datetime 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') + morningstart.read() + linelist = morningstart.readline() + operstamp = getpass.getuser() + timestamp = datetime.datetime.now().strftime('%Y%m%d-%H:%M:%S') with open('updates.txt', 'a') as dailyupdates: - print('This is your last update: ') - print (linelist) - print('What are your updates?') - typedupdates = input() - nline = "\n" - iline = " -- " - dailyupdates.write(operstamp) - dailyupdates.write(iline) - dailyupdates.write(timestamp) - dailyupdates.write(nline) - dailyupdates.write(typedupdates) - ender = "\nEOF-------------------------------------------EOF\n\n" - dailyupdates.write(ender) + print('This is your last update: ') + print (linelist) + print('What are your updates?') + typedupdates = input() + nline = "\n" + iline = " -- " + dailyupdates.write(operstamp) + dailyupdates.write(iline) + dailyupdates.write(timestamp) + dailyupdates.write(nline) + dailyupdates.write(typedupdates) + ender = "\nEOF-------------------------------------------EOF\n\n" + dailyupdates.write(ender)