How can we check the data of binary file?
- We need to perform de-serialization programmatically to get the actual information of that binary file.
- Pickle.load() function is used to perform de-serialization.
- Load() function returns Object form of that binary data.
deserialize.py:
import pickle
from emp import Employee
class DeSerialization:
file = None
def main():
try :
DeSerialization.file = open("./data.bin", mode="rb")
print("File is ready")
obj = pickle.load(DeSerialization.file)
print("Object is De-serialized successfully")
print("Employee details are :")
print("Emp num :", obj.num)
print("Emp name :", obj.name)
print("Emp salary :", obj.salary)
except Exception as e:
print("Exception :", e)
finally:
if DeSerialization.file != None:
DeSerialization.file.close()
print("File closed")
return
DeSerialization.main()
Run deserialize.py: