I am looping over a list containing 9 file names and trying to create 9 variables (i.e. one for each file that I open).
The code seems to import correctly but I cant get it to create 9 variables, I've only managed to create one.
Code that works and creates one list (the 9th file):
for i in category_list:
j = category_list.index(i)
with open(str(path) + category_list[j] + f_ext, 'rb') as f:
d = pickle.load(f)
Code that gives me error "name 'd_' is not defined
for i in category_list:
j = category_list.index(i)
with open(str(path) + category_list[j] + f_ext, 'rb') as f:
d_[i] = pickle.load(f)
I think I may need to either declare the variable (which doesn't feel right for python) or I'm missing something even more simple.
Appreciate any help.
Thanks.
1 Answer 1
hm... it seams it may works:
d_ = []
for category in category_list:
with open(str(path) + category + f_ext, 'rb') as f:
d_.append( pickle.load(f))
Isn't it? If - it is so - try eat more Python-like code )
d_; I assume it's supposed to be a list. And as Vasyl Kolomiets said, your indentation is broken.for idx, item in enumerate(my_sequence):