Python Forum
Writing in a document problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Writing in a document problem
#1
Bug 
Hi everyone, i'm French and i try to code in python language. In university we have to code in html/xml and i try to developp an app that put automaticaly the sentences between html tags. I'm only at the begining of said programm. There is the code :
from os import chdir
chdir("/home/jean/Documents/fac/info/fable_python")

#I open my text document in wich is my titles in writing mode. And i create/open second one wich #will be the "html" document. 

folderFab=open(("liste_fable"),'r')
tei=open(("liste_fable2.txt"),'w')

#I try the process with only ten titles for more clarity in the results

for i in range(10):
	t=str(folderFab.readline())
	s='<title>'+ t +'</title>'
	tei.write(s)	

folderFab.close()
tei.close()
unfortunately it give the following result :

<title>Le Dépositaire infidèle
</title><title>Les Deux Pigeons
</title><title>Le Singe et le Léopard
</title><title>Le Gland et la Citrouille
</title><title>L’Écolier, le Pédant et le Maître d’un jardin
</title><title>Le Statuaire et la Statue de Jupiter
</title><title>La Souris métamorphosée en fille
</title><title>Le Fou qui vend la Sagesse
</title><title>L'Huître et les Plaideurs
</title><title>Le Loup et le Chien maigre
</title>

I dont know why, i wanted something looking like, for exemple : <title>Le singe et le Léopard</titles>
I already tried to change the var type in string i the "s" variable. Someone have any idea ?

Thanks,
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
  writing list to csv file problem jacksfrustration 1 35 32 minutes ago
Last Post: deanhystad
  problem writing dataframe to oracle aliyesami 4 2,795 Sep-25-2021, 11:20 PM
Last Post: SamHobbs
  Problem writing a variable value to Excel Chuck_Norwich 1 2,023 Jul-25-2019, 02:20 PM
Last Post: Chuck_Norwich
  Problem with reading and writing to file. darktitan 2 2,406 Jul-20-2019, 06:06 PM
Last Post: darktitan
  Writing Answers From Questionnaire to a new .txt Document FizzyBreak579 4 3,733 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