()
| 2 | |
| 3 | |
| 4 | def binary_read(): |
| 5 | with open("studrec.dat", "rb") as b: |
| 6 | stud = pickle.load(b) |
| 7 | print(stud) |
| 8 | |
| 9 | # prints the whole record in nested list format |
| 10 | print("contents of binary file") |
| 11 | |
| 12 | for ch in stud: |
| 13 | print(ch) # prints one of the chosen rec in list |
| 14 | |
| 15 | rno = ch[0] |
| 16 | rname = ch[1] # due to unpacking the val not printed in list format |
| 17 | rmark = ch[2] |
| 18 | |
| 19 | print(rno, rname, rmark, end="\t") |
| 20 | |
| 21 | |
| 22 | binary_read() |