This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: file.readline() cannot read weird ascii character in file
Type: behavior Stage:
Components: IO Versions: Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: Tony.Malykh, amaury.forgeotdarc
Priority: normal Keywords:

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:31adminsetgithub: 59334
2012-06-21 22:05:46amaury.forgeotdarcsetstatus: open -> closed

nosy: + amaury.forgeotdarc
messages: + msg163373

resolution: wont fix
2012-06-21 20:36:27Tony.Malykhcreate