Bonjour,
Je m'acharne tant bien que mal a vouloir compter le nombre de lignes d'un fichier.
Le problème c'est à un moment de parsage du fichier, je vois une erreur "UnicodeDecodeError" apparaître.
Script:
Erreur:
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 import io def file_lengthy(fname): #with open(fname,encoding='utf-8') as f: with io.open(fname) as f: for i, l in enumerate(f): print(l.rstrip("\n")) pass return i + 1 #wordfile to use wordfile = "/home/gr3g/ctf/wordlist/rockyou.txt" #print("Number of lines in the file: ",file_lengthy("test.txt")) print("Number of lines in the file: ",file_lengthy(wordfile))
La suite du dictionnaire c'est :$ python3 filelength.py
[...]
pernille1
pernes
pernambucano
permatang
permataku
permatahati
Traceback (most recent call last):
File "filelength.py", line 15, in <module>
print("Number of lines in the file: ",file_lengthy(wordfile))
File "filelength.py", line 6, in file_lengthy
for i, l in enumerate(f):
File "/usr/lib/python3.5/codecs.py", line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf1 in position 940: invalid continuation byte
601939 perman
601940 permainan
601941 perlucha
601942 perliza
601943 perlittapmf
601944 perlita99
601945 perling
601946 perlax
601947 perlar
601948 perlamassiel
601949 perlam
601950 perla8
601951 perla21
601952 perla10
601953 perl1ta
601954 perky2
601955 perkutut
Donc il n'y a pas de mots qui nécessitent un encodage spécifique si ?
Merci
Partager