Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32684
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'output': 0.04; 'none,': 0.05; 'python3': 0.05; 'default.': 0.07; 'enabled.': 0.07; 'means,': 0.07; 'newline': 0.07; 'sys,': 0.07; 'python': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; "skip:' 30": 0.15; 'skip:p 40': 0.15; 'fix:': 0.16; "isn't.": 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'wrote:': 0.17; '3.2': 0.22; 'latter': 0.22; 'universal': 0.22; 'header:User-Agent:1': 0.26; 'skip:" 20': 0.26; 'header:X -Complaints-To:1': 0.28; '+0100,': 0.29; '3.1': 0.29; 'cat': 0.29; "d'aprano": 0.29; 'steven': 0.29; "skip:' 10": 0.30; 'fri,': 0.30; 'to:addr:python-list': 0.33; 'nov': 0.35; 'received:org': 0.36; 'but': 0.36; 'should': 0.36; 'skip:p 20': 0.36; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'start-up,': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: enabling universal newline |
| Date | Sat, 03 Nov 2012 09:26:39 +0100 |
| Organization | None |
| References | <alpine.DEB.2.00.1211022316290.2869@pebbe> <509452ae$0$29967$c3e8da3$5496439d@news.astraweb.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p50849822.dip.t-dialin.net |
| User-Agent | KNode/4.7.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3232.1351931198.27098.python-list@python.org> (permalink) |
| Lines | 30 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1351931198 news.xs4all.nl 6890 [2001:888:2000:d::a6]:50521 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:32684 |
Show key headers only | View raw
Steven D'Aprano wrote:
> 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?
$ python3 -c 'open("tmp.txt", "wb").write(b"a\nb\r\nc\rd")'
This is the output with universal newlines:
$ python3 -c 'print(open("tmp.txt").readlines())'
['a\n', 'b\n', 'c\n', 'd']
But this is what you get from stdin:
$ cat tmp.txt | python3 -c 'import sys; print(sys.stdin.readlines())'
['a\n', 'b\r\n', 'c\rd']
With Peter Kleiweg's fix:
$ cat tmp.txt | python3 -c 'import sys, io; print(io.TextIOWrapper(sys.stdin.detach(), newline=None).readlines())'
['a\n', 'b\n', 'c\n', 'd']
I think it's reasonable to make the latter the default.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
enabling universal newline Peter Kleiweg <pkleiweg@xs4all.nl> - 2012-11-02 23:22 +0100
Re: enabling universal newline Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-02 23:09 +0000
Re: enabling universal newline Peter Otten <__peter__@web.de> - 2012-11-03 09:26 +0100
Re: enabling universal newline Peter Kleiweg <pkleiweg@xs4all.nl> - 2012-11-03 09:30 +0100
csiph-web