I am using a dictionary to add key and values in it. I am checking if the key is already present, and if yes, I am appending the value; if not I add a key and the corresponding value.
I am getting the error message:
AttributeError: 'str' object has no attribute 'append'
Here is the code. I am reading a CSV file:
metastore_dir = collections.defaultdict(list)
with open(local_registry_file_path + data_ext_dt + "_metastore_metadata.csv",'rb') as metastore_metadata:
for line in metastore_metadata:
key = line[2]
key = key.lower().strip()
if (key in metastore_dir):
metastore_dir[key].append(line[0])
else:
metastore_dir[key] = line[0]
I found the answer on stack overflow which says to use defaultdict to resolve the issue, i am getting the error message even after the suggested anwer. I have pasted my code for reference.