n documentation’s stern security warnings about pickle. However, pickle has been used to serialize objects for many years, so you’re likely to encounter it in Python legacy code. using the pickle module’s dump function to serialize the dictionary into a file and its load function to deserialize the object. Pickle is a binary format, so this exercise requires binary files. ”Reimplement your solutions to Exercises 9.6. Use the file-open mode 'wb' to open the binary file for writing and 'rb' to open the binary file for reading. Function dump recei

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Topic Video
Question

(pickle Object Serialization and Deserialization) We mentioned that we prefer to use JSON for object serialization due to the Python documentation’s stern security warnings about pickle. However, pickle has been used to serialize objects for many years, so you’re likely to encounter it in Python legacy code.

using the pickle module’s dump function to serialize the dictionary into a file and its load function to deserialize the object. Pickle is a binary format, so this exercise requires binary files.

”Reimplement your solutions to Exercises 9.6. Use the file-open mode 'wb' to open the binary file for writing and 'rb' to open the binary file for reading. Function dump receives as arguments an object to serialize and a file object in which to write the serialized object. Function load receives the file object containing the serialized data and returns the original object. The Python documentation suggests the pickle file extension .p

Excercise 9.6 code

import json


def main():
n = int(input("Enter the number of students: "))
data = []

for i in range(n):
first = input("\nEnter First Name of Student " + str(i + 1) + ": ")
last = input("Enter Last Name of Student " + str(i + 1) + ": ")
te1 = int(input("Enter Te_st 1 Grade of Student " + str(i + 1) + ": "))
te2 = int(input("Enter Te_st 2 Grade of Student " + str(i + 1) + ": "))
te3 = int(input("Enter Te_st 3 Grade of Student " + str(i + 1) + ": "))
info = {}
info['first_name'] = first
info['last_name'] = last
info['ex_am1'] = te1
info['ex_am2'] = te2
info['ex_am3'] = te3
data.append(info)
gradebook_dict = {'students': data}

with open("grades.json", 'w') as _file:
json.dump(gradebook_dict, _file, indent=4)
print("\nWriting Done.\n")

with open("grades.json", 'r') as _file:
data = (json.load(_file))['students']
print(f'{"First Name":>15} {"Last Name":>15} {"test 1":>6} {"test 2":>6} {"test 3":>6} {"average":>7}')
totalTest1 = 0
totalTest2 = 0
totalTest3 = 0
count = 0
for i in data:
t1 = i['ex_am1']
t2 = i['ex_am2']
t3 = i['ex_am3']
totalTest1 += t1
totalTest2 += t2
totalTest3 += t3
count += 1
fname = i['first_name']
lname = i['last_name']
avg = (t1 + t2 + t3) / 3
print(f"{fname:>15} {lname:>15} {t1:>6d} {t2:>6d} {t3:>6d} {avg:>7.2f}")
print("-" * 60)
print(f"{'Test average':<32} {totalTest1 / count:>6.2f} {totalTest2 / count:>6.2f} {totalTest3 / count:>6.2f}")


main()

Expert Solution
Step 1

The answer is an given below :

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education