Issue 15129: file.readline() cannot read weird ascii character in file (original) (raw)

Issue15129

Created on 2012-06-21 20:36 by Tony.Malykh, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
testpy.zip Tony.Malykh,2012-06-21 20:36
Messages (2)
msg163363 - (view) Author: Tony Malykh (Tony.Malykh) Date: 2012-06-21 20:36
readline() or readlines() method can read the file up to the line where weird character ascii code 26 appears. I would like to read the entire file though. A simple example attached.
msg163373 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2012-06-21 22:05
Your problem is similar to this discussion: http://stackoverflow.com/questions/405058/line-reading-chokes-on-0x1a On Python2, files are based on the fopen() C function, and on Windows files opened in text mode stop reading on the first character 26 (^Z, or EOF) The best solution here is probably to open the file in "universal" mode: f = open("test.txt", "rU") ...Or use Python3, which has a completely new implementation of the open() function.
History
Date User Action Args
2022-04-11 14:57:31 admin set github: 59334
2012-06-21 22:05:46 amaury.forgeotdarc set status: open -> closednosy: + amaury.forgeotdarcmessages: + resolution: wont fix
2012-06-21 20:36:27 Tony.Malykh create