Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!feeder1.xsusenet.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.062 X-Spam-Evidence: '*H*': 0.88; '*S*': 0.00; 'happen,': 0.09; 'subject:set': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'f.tell()': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:when': 0.16; 'tried:': 0.16; 'weird.': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'bit': 0.19; 'cc:addr:python.org': 0.22; 'byte': 0.24; 'cc:2**0': 0.24; 'header :In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; '>>>>': 0.31; 'assert': 0.31; 'pipe': 0.31; 'file': 0.32; 'another': 0.32; 'text': 0.33; "i'd": 0.34; 'done.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'version': 0.36; 'really': 0.36; 'done': 0.36; 'possible': 0.36; 'subject:?': 0.36; 'being': 0.38; 'checks': 0.38; 'writes': 0.38; 'rather': 0.38; 'even': 0.60; 'read': 0.60; "you're": 0.61; 'subject:get': 0.81; '2015': 0.84; 'moves': 0.84; 'otten': 0.84; 'inefficient': 0.91; 'to:none': 0.92; 'convinced': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=H0jOgbeVh0y2IyvvmMFrwEe6wiBnZ9Jjjpe4cKoA1Bw=; b=r8z6+qePl9XT/aYLDmwEV0c6e7LEor8nXYfUYMpfxDIexZTBIp7iNWSD5ONgS5b8Ix S/xByC8ZjC+bF49cmSj1Y3uNrc0vO56BzbQLkSwPhtkkRIQRKvQqPpNxvZUxo7r86tTv n6+AJ/e0cfIefUyUZosutAAXCOACKxqwe6jog0ze+Uf+twcfmf3tzlPZErD/NNDDZfZS UxkTCXYaZecRGur2xb8rouHTDmnz3VmKWbHvXvLl8DG2MPTfUYOJHRDOwCbYJ+gT99g+ ZJQYueGE//dyiTB8nHHdMsyWhFBHOfQ17bMQJC5MDmhzMRYLvY8a50JCftWBuW9eVuvS TRuQ== MIME-Version: 1.0 X-Received: by 10.50.43.196 with SMTP id y4mr13726642igl.14.1430753205231; Mon, 04 May 2015 08:26:45 -0700 (PDT) In-Reply-To: References: <3c45772b-77e0-4c17-8b3d-aa246c4b511c@googlegroups.com> Date: Tue, 5 May 2015 01:26:45 +1000 Subject: Re: when does newlines get set in universal newlines mode? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1430753207 news.xs4all.nl 2917 [2001:888:2000:d::a6]:53302 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:89910 On Tue, May 5, 2015 at 1:17 AM, Peter Otten <__peter__@web.de> wrote: > OK, you convinced me. Then I tried: > >>>> with open("tmp.txt", "wb") as f: f.write("0\r\n3\r5\n7") > ... >>>> assert len(open("tmp.txt", "rb").read()) == 8 >>>> f = open("tmp.txt", "rU") >>>> f.readline() > '0\n' >>>> f.newlines >>>> f.tell() > 3 >>>> f.newlines > '\r\n' > > Hm, so tell() moves the file pointer? Is that sane? ... wow. Okay! That's a bit weird. It's possible that something's being done with internal buffering (after all, it's horribly inefficient to *actually* read text one byte at a time, even if that's what's happening conceptually), and that tell() causes some checks to be done. But that really is rather strange. I'd be interested to know what happens if another process writes to a pipe "0\r", then sleeps while the readline() and tell() happen, and then writes a "\n" - what will that do to newlines? By the way, it's as well to clarify, with all these examples, what Python version you're using. There may be significant differences. ChrisA