Используя описание вместо desc для таблицы2,
update
table1
set
value = (select code from table2 where description = table1.value)
where
exists (select 1 from table2 where description = table1.value)
and
table1.updatetype = 'blah'
;
Поместите сами объекты file
в словарь, а не имена файлов.
files_dict = {}
with open(data_in) as fi:
for line in fi:
x = line.split(',')[1]
if x not in files_dict:
fo = open(x + '.csv', "w")
files_dict[x] = fo
else:
fo = files_dict[x]
fo.write(x)
for fo in files_dict.values():
fo.close()
У вас есть правильная идея, но вы должны хранить файловые объекты, а не имена файлов в dict, и вам не нужен блок else
(который должен был быть выровнен с if
, а не for
):
files_dict = {}
with open(data_in) as fi:
for line in fi:
x = line.split(',')[1]
if x not in files_dict:
files_dict[x] = open(x + '.csv', 'w')
files_dict[x].write(line)
for file in files_dict.values():
file.close()