I am trying to take in all the files at a given path, and order them based on my data title names. So my data title names are:
data_titles = ['CPU','Physical_Disk','Memory','Network']
The files at this given path are named like 'CPU_data.txt' and 'Memory_data.txt' but there are also some that have more than one file per data title for example 'Physical_Disk_data_1.txt' and 'Physical_Disk_data_2.txt'.
I am trying to create a dicitonary in the style of:
{'Network': 'Network_data.txt',
'Physical_Disk': ['Physical_Disk_data_1.txt','Physical_Disk_data_2.txt'],
'CPU': 'CPU_data.txt',
'Memory': 'Memory_data.txt'}
i.e not overwriting older values
However I keep getting the error AttributeError: 'dict' object has no attribute 'update', if I use append instead of update I get a similar error AttributeError: 'dict' object has no attribute 'append'
table_csv_files={}
for file_names in os.listdir(Data_folder):
for name in data_titles:
if name in file_names:
if name in table_csv_files:
table_csv_files[name].update(file_names)
# Have also tried table_csv_files.append({name:file_names})
else:
table_csv_files[name]=file_names
print table_csv_files
What am I doing wrong?