So I'm trying to define a function that takes a pickle file and one or more keys as parameters and then returns the values for the keys called from said pickle file. I'm having trouble figuring out how to call multiple keys within the function. This is what I have so far:
import pickle
def read_keys(picklefile, keys):
file = open(picklefile, "rb")
loaded_dictionary = pickle.load(file)
for key in loaded_dictionary.keys:
if key in keys:
return
if "Name" in loaded_dictionary:
name = loaded_dictionary["Name"]
else:
name = None
if "City" in loaded_dictionary:
city = loaded_dictionary["City"]
else:
city = None
if "Address" in loaded_dictionary:
address = loaded_dictionary["Address"]
else:
address = None
return
print(read_keys('isabel.pickle', ['Name'], ['City']))
print(read_keys('mamadou.pickle', ['Name'], ['City'], ['Address']))
I keep getting this error:
`---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-2bbef15443a2> in <module>
26
27
---> 28 print(read_keys('isabel.pickle', ['Name'], ['City']))
29 print(read_keys('mamadou.pickle', ['Name'], ['City'], ['Address']))
TypeError: read_keys() takes 2 positional arguments but 3 were given
`