Python Forum
Writing in a document problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Writing in a document problem
#5
(Oct-26-2022, 02:40 PM)snippsat Wrote: You can loop direclty over the file object,and range() is not nessesary.
Try to use with 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 Smile
Reply


Messages In This Thread
Writing in a document problem - by IOHANNES - Oct-26-2022, 11:45 AM
RE: Writing in a document problem - by wavic - Oct-26-2022, 12:10 PM
RE: Writing in a document problem - by IOHANNES - Oct-26-2022, 12:57 PM
RE: Writing in a document problem - by snippsat - Oct-26-2022, 02:40 PM
RE: Writing in a document problem - by IOHANNES - Oct-26-2022, 08:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem writing dataframe to oracle aliyesami 4 2,766 Sep-25-2021, 11:20 PM
Last Post: SamHobbs
  Problem writing a variable value to Excel Chuck_Norwich 1 1,998 Jul-25-2019, 02:20 PM
Last Post: Chuck_Norwich
  Problem with reading and writing to file. darktitan 2 2,361 Jul-20-2019, 06:06 PM
Last Post: darktitan
  Writing Answers From Questionnaire to a new .txt Document FizzyBreak579 4 3,696 Feb-16-2018, 07:26 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020