You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
file.readline() cannot read weird ascii character in file #59334
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.
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.
Activity
TonyMalykh commentedon Jun 21, 2012
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.
amauryfa commentedon Jun 21, 2012
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.