Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
reading in a doc
#1
Hi i come back with a problem. Again. I code the second module of my program, this one have to match two docs, one containing a novel's list and the second one a keywords list. If there is a match the word corresponding is placed between two tags.

here is the code :


def baliseAnimaux(mot,motClef,dossierEcrire):
	
	nbLine=0 #number of lines of first document, a list of novel's titles
	nbLine2=0 #numbre of line of second document, in wich is the keywords the program have #match
	keyword=False
	r=0
#searching how many lines contain each document 	
	for a in mot:
		nbLine += 1
		
	for e in motClef:
        	nbLine2 += 1
	mot.seek(0)
	motClef.seek(0)
	
	for b in range(nbLine):		#for each line of doc to compare
		motA=str(mot.readline()) 
		phrase=motA.split(" ")   
		for i in range(len(phrase)): # for each word in each sentences			
			for j in range(nbLine2): # i read each lines of the keywords doc
				motD=str(motClef.readline()) 
				#motC=motD.split("\n") #isoler la ligne
				print(motD)# here it's just a test
				for h in range(nbLine2):	#					
					if phrase[i] == motD or phrase[i] == "l'"+motD :
						keyword=True					
						break				
					elif phrase[i]!=motD or phrase[i]!="l'"+motD:	
						keyword=False
							
					
								
			
			if keyword == True :			
				dossierEcrire.write("<persname>")
				dossierEcrire.write(phrase[i])
				dossierEcrire.write("<persname>")
				dossierEcrire.write(" ")
			else :
				dossierEcrire.write(phrase[i])
				dossierEcrire.write(" ")
						
i have no error, the final document is filled as expected, but idk when i print(motD), there is nothing written. someone could help me ?

thanks At
Reply
#2
Nothing to print?

Try to change it

print(j, motD)
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
(Oct-27-2022, 11:17 AM)wavic Wrote: Nothing to print?

Try to change it

print(j, motD)

I tried but when i do it, i have the the "j" values but whith nothing. I dont understand why this append.
Reply
#4
Non-printable characters?

You may try print(bytes(motD, 'utf-8'))
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#5
Can you post a small example of your data: mot, motClef and dossierEcrire?

I have trouble imagining what they might or should look like.

mot is French for word, if I remember my school French and clef is key?

So, you pass a word and a key to baliseAnimaux(mot,motClef,dossierEcrire)
wavic likes this post
Reply


Forum Jump:

User Panel Messages

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