die file.readline() Funktion macht mir bei Python 3 Probleme.
Wenn ich z.B. folgende Code-Zeilen habe...
Code: Alles auswählen
f = open("text.txt")
for line in f:
print(line) # bzw. print line
Traceback (most recent call last):
File "C:\...\test.py", line 13, in <module>
for line in fp:
File "C:\Python30\lib\io.py", line 1744, in __next__
line = self.readline()
File "C:\Python30\lib\io.py", line 1817, in readline
while self._read_chunk():
File "C:\Python30\lib\io.py", line 1565, in _read_chunk
self._set_decoded_chars(self._decoder.decode(input_chunk, eof))
File "C:\Python30\lib\io.py", line 1299, in decode
output = self.decoder.decode(input, final=final)
File "C:\Python30\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 1105: character maps to <undefined>
Die Zeilen, über die Python stolpert, unterscheiden sich in nichts vom restlichen Inhalt der Datei. Also keine Umlaute oder irgendwelche wirren Zeichen..
Hat jemand eine Idee, wo der Fehler steckt? Danke vielmals!
P.S.: In einer früheren Version dieses Beitrages stand oben im Code print(x) anstatt print(line). Das ist natürlich Quatsch, sorry dafür..