write eof without closing

Alex Martelli aleax at mac.com
Mon Aug 21 00:10:32 EDT 2006


Grant Edwards <grante at visi.com> wrote:
   ...
> IIRC, ctrl-Z is not used _in_files_ to represent EOF.  Only
> when text is being entered at the console.

Easy to test, if you have Windows:

>>> n='foo.txt'
>>> s='ba\r\n'+chr(26)+'bo\r\r'
>>> open(n,'wb').write(s)
>>> ss=open(n).read()
>>> ss
'ba\n'

As you see, in _text_ files on Windows a control-Z (char(26), AKA
'\x1a') does indeed represent "end of file" -- a convention going back
to CP/M (which lacked metadata to represent file length except in
multiples of 256 characters, if I recall correctly) and is still
followed by Windows (and by Python running on Windows).

Nevertheless I doubt it would help the original poster -- I think, like
/F and you, that a line-end and flush may be what he needs.


Alex



More information about the Python-list mailing list