Bonjour a tous
pour charger un fichier .txt j'ai fait ça
mais une erreur UnicodeWarning s'affiche dans la ligne
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 def charge_fichier(nomFile,cpt_doc): global nb_doc f=codecs.open(nomFile,'r','utf-8') if(not f):return 0; nb_doc+=1; t=f.read() t=t.lower() a=t.split() for mot in a: if(not (mot,cpt_doc) in freq0 ): freq0[mot,cpt_doc]=a.count(mot) n0[mot]+=1 f.close() for (mot ,doc) in freq0 : poid0[mot,doc]=freq0[mot,doc]*log(nb_doc/n0[mot]+1,10) ## bool index_bool(indexBoolean_0,a,cpt_doc); a=[porteur.stem(x)for x in a if not x in ignored_words] for mot in a: if(not (mot,cpt_doc) in freq1 ): freq1[mot,cpt_doc]=a.count(mot) n1[mot]+=1 f.close() for (mot ,doc) in freq1 : poid1[mot,doc]=freq1[mot,doc]*log(nb_doc/n1[mot]+1,10) index_bool(indexBoolean_1,a,cpt_doc); return 1;
Code : Sélectionner tout - Visualiser dans une fenêtre à part a=[porteur.stem(x)for x in a if not x in ignored_words]
comme suite :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 a=[porteur.stem(x)for x in a if not x in ignored_words] UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
pour éviter cette erreur j'ai enregistré le fichier en UTF-8 ''notpade++''
et j'ai fait ça aussi
mais toujours la meme erreur s'affiche
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 # -*- coding: utf-8 -*- import codecs
Merci pour vos repense![]()
Partager