-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssignment07.py
44 lines (35 loc) · 1.24 KB
/
Assignment07.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#----------------------------------------------------------------------------------------------#
# Title: Pickling, Exceptions
# Dev: Letha
# Date: Feb 24, 2019
# ChangeLog: (Who, When, What)
# Letha, 02/24/2019, Created script
#----------------------------------------------------------------------------------------------#
# Import the Pickle module so that I can pickle and unpickle data
import pickle
# Declare variable
lstPagerDuty = []
# Unpickle data from pagerduty.dat file using pickle.load method
# Use exception handling
try:
objFile = open("pagerduty.dat", "rb")
objFileData = pickle.load(objFile)
objFile.close()
print("Current pager duty assignment: \n")
print(objFileData)
# Exception in case there is no pagerduty.dat file or no data
except:
print("Pager duty isn't yet assigned.\n")
# Identify who is on pager duty this week
strName = input("Who is on pager duty next? ")
strPhone = input("What's their phone number? ")
lstPagerDuty = [strName, strPhone]
print("Pager duty assigned: \n")
print(lstPagerDuty)
print("\n")
# Store the data using the pickle.dump method
objFile = open("pagerduty.dat", "wb")
pickle.dump(lstPagerDuty, objFile)
objFile.close()
# End this script
input ("\n\nPress the Enter key to exit.")