I'm trying to read a series of dictionaries from a file:
GFG.txt
{'geek': 10, 'geeky': True}
{'GeeksforGeeks': 'Education', 'geekgod': 101.0, 3: 'gfg'}
{'supergeek': 5}
and I found this website with the following solution:
import pickle
geeky_file = open('GFG.txt', 'r')
dictionary_list = pickle.load(geeky_file)
for d in dictionary_list:
print(d)
geeky_file.close()
However this throws an exception:
TypeError: a bytes-like object is required, not 'str'
Opening the file in binary mode:
geeky_file = open('GFG.txt', 'rb')
gives me the error:
UnpicklingError: invalid load key, '{'.