Я пытаюсь назвать несколько имен файлов json, которые анализируются из файлов xml. Каждый файл json содержит информацию о дате, которую я хочу включить в название каждого файла, например speech_26_01_2000.json
Я пытался использовать этот код:
speech_file = 'speech_{}_{}.json'.format(date, speech_idx.replace('.','_'))
Но в коде указана эта датане определено
Обычно код хранит информацию о дате здесь:
for line in lines:
txt = line.text.strip()
if 'Es gilt das gesprochene' in txt:
title, date, author = process_init_page(lines)
init_pages.append({page['pageid']: (title, date, author)})
content[page['pageid']] = {'TITLE': title, 'DATE': date, 'AUTHOR': author, 'DATE': date,
'SECTION': 'reden', 'RECORD_ID': date}
И процесс выгрузки:
title_page_info, pages_object = process_file(pdf_file)
if len(pages_object) > 0:
print('FOLDER_NAME = {} CREATED...'.format(FOLDER_NAME))
if not os.path.exists(FOLDER_NAME):
os.makedirs(FOLDER_NAME)
resultant = dump_text(pages_object, title_page_info)
speech_idx = 0
for result in resultant:
speech_idx += 1
speech_file = 'speech_{}_{}.json'.format(date, speech_idx.replace('.','_'))
#speech_file = 'speech_{}.json'.format(speech_idx) this code works
with open(FOLDER_NAME + '/' + speech_file, 'a+', encoding='utf8') as f_speech:
f_speech.write(json.dumps(result, ensure_ascii=False))
except Exception as ex:
print('Exception in process file')
print(str(ex))
finally:
print('DONE')
Как упоминалось в коде, речь _ {}. Json работает. Но мне нужны разные даты в имени файла и я не знаю, как туда добраться.