Oct-26-2022, 08:58 PM
(Oct-26-2022, 02:40 PM)snippsat Wrote: You can loop direclty over the file object,andrange()
is not nessesary.
Try to usewith open
then no need to close file obejct,also using f-sting make it nicer.
Then it can be done like this.
with open('list_fable.txt') as fp,open('list_out.html', 'w') as fp_out: for line in fp: fp_out.write(f'<title>{line.strip()}</title>\n')list_out.html:
Output:<title>Le Dépositaire infidèle</title> <title>Les Deux Pigeons</title> <title>Le Singe et le Léopard</title>
very clear thanks