enabling universal newline
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Fri Nov 2 19:09:34 EDT 2012
On Fri, 02 Nov 2012 23:22:53 +0100, Peter Kleiweg wrote:
> In Python 3.1 and 3.2
>
> At start-up, the value of sys.stdin.newlines is None, which means,
> universal newline should be enabled. But it isn't.
What makes you think it is not enabled?
sys.stdin.newlines shows you the newlines actually seen. Until you put
text including newlines through stdin, it will remain None.
http://docs.python.org/2/library/stdtypes.html#file.newlines
http://docs.python.org/3/library/io.html#io.TextIOBase.newlines
For example, I have Python built with universal newlines, but
stdin.newlines remains None:
py> f = open('test.txt')
py> f.newlines
py> f.readlines()
['a\n', 'b\n', 'c\n', 'd\n']
py> f.newlines
('\r', '\n', '\r\n')
py> sys.stdin.newlines is None
True
--
Steven
More information about the Python-list
mailing list