...

/

Serialization and Deserialization

Serialization and Deserialization

Learn about the serialization and deserialization of data using the json module in Python.

Compared to strings, reading/writing numbers to and from a file is tedious. This is because the write() function writes a string to a file and the read() function returns a string read from a file. So we need to do conversions while reading/writing, as shown in the following program:

Press + to interact
f = open('numberstxt', 'w+')
f.write(str(233)+'\n')
f.write(str(13.45))
f.seek(0)
a = int(f.readline( ))
b = float(f.readline( ))
print(a + a)
print(b + b)

If we want ...