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.
Created on 2014年03月30日 18:02 by Alex.Grinko, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| sample.txt | Alex.Grinko, 2014年03月30日 18:02 | Sample file with lines and special character | ||
| Messages (2) | |||
|---|---|---|---|
| msg215190 - (view) | Author: Alex Grinko (Alex.Grinko) | Date: 2014年03月30日 18:02 | |
When reading from text file on Windows Python ends loop on character 0x1A
sample.py:
number = 0
with open("sample.txt",'r') as f:
for line in f:
number += 1
print line
print "File has 8 lines, but Python could read only ",number
|
|||
| msg215203 - (view) | Author: Eryk Sun (eryksun) * (Python triager) | Date: 2014年03月30日 21:26 | |
AFAIK, this doesn't affect Python 3 under normal circumstances. A file could be manually set to text mode by calling msvcrt.setmode(f.fileno(), os.O_TEXT), but that's out of the norm. In Python 2, on Windows interpreting ctrl+z (0x1a) as end-of-file is normal behavior in text mode. Read the remarks about [t]ext mode in the description of Microsoft's fopen implementation: http://msdn.microsoft.com/en-us/library/yeby3zcb%28v=vs.90%29.aspx If you use Python's universal newlines mode, e.g. open('sample.txt', 'rU'), then the underlying file is opened in binary mode and therefore will not interpret ctrl+z as the end-of-file marker. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:01 | admin | set | github: 65303 |
| 2014年03月31日 06:35:53 | Alex.Grinko | set | status: open -> closed resolution: works for me |
| 2014年03月30日 21:26:33 | eryksun | set | nosy:
+ eryksun messages: + msg215203 |
| 2014年03月30日 18:02:23 | Alex.Grinko | create | |