Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.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.099 X-Spam-Evidence: '*H*': 0.82; '*S*': 0.01; 'raises': 0.09; 'subject:set': 0.09; 'exception?': 0.16; 'f.tell()': 0.16; 'subject:when': 0.16; 'tried:': 0.16; 'followed': 0.16; 'wrote:': 0.18; 'mon,': 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; 'maybe': 0.34; 'received:google.com': 0.35; 'next': 0.36; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'expect': 0.39; 'to:addr:python.org': 0.39; 'safe': 0.72; 'subject:get': 0.81; '2015': 0.84; 'moves': 0.84; 'otten': 0.84; '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:from:date:message-id:subject:to :content-type; bh=s0jEc72Rx+eriWQ8RaGsqFpYox+ptfuiEjqH8U9luQU=; b=wo4LI4D1/EcUcC8yAeZT8ImLLzALe+Ci3iu53pqR9vYfVb12Gw3HQL0yrAP91khpaT ql+niogx4l3MV3MgNtFkelNi5zoOFty38bLizKEWqlskYO7yTuCbWtmlMnxjFbx/wc+n bc+wNcxJe899es0kffBe2xO4IdXns+qu8aH6UHi5xc2FgKCZekkaDIMfP8y2MlEW5sO1 RSa6al+JSJR7nM8mlqBRk682Y5+f3+7Flpmr3zG+gl4euXA3ZflbWe/7YUnjmuTdM62N 2o7i3sRpmPD78gwt9SxIjRfV1/XfY0ngDzUyW6Qzk5BMrGvha/2u0J/cfbXUNNIJz3C3 fVAQ== X-Received: by 10.50.142.98 with SMTP id rv2mr13926018igb.11.1430753670846; Mon, 04 May 2015 08:34:30 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <3c45772b-77e0-4c17-8b3d-aa246c4b511c@googlegroups.com> From: Ian Kelly Date: Mon, 4 May 2015 09:33:50 -0600 Subject: Re: when does newlines get set in universal newlines mode? To: Python 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: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1430753672 news.xs4all.nl 2962 [2001:888:2000:d::a6]:57166 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:89911 On Mon, May 4, 2015 at 9: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? If I call readline() followed by tell(), I expect the result to be the position of the start of the next line. Maybe this is considered safe because tell() on a pipe raises an exception?