Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'level,': 0.07; 'string': 0.09; 'newline': 0.09; 'parsed': 0.09; 'style.': 0.09; "wouldn't": 0.14; "'rb')": 0.16; 'encodings': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'quoted': 0.16; 'respected.': 0.16; 'simple.': 0.16; 'wrote:': 0.18; 'else,': 0.19; 'thu,': 0.19; 'import': 0.22; 'aug': 0.22; 'earlier': 0.24; '(or': 0.24; 'source': 0.25; '15,': 0.26; 'handling': 0.26; 'header:In-Reply- To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; '>>>>': 0.31; 'are.': 0.31; 'file': 0.32; 'something': 0.35; 'received:google.com': 0.35; 'disk': 0.36; 'to:addr:python-list': 0.38; 'expect': 0.39; 'to:addr:python.org': 0.39; 'read': 0.60; 'information': 0.63; 'actually,': 0.84; 'dealt': 0.91; '2013': 0.98 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:to :content-type; bh=AVsAjbLQErkFW91fPjPLg1Sy2NxqBBqdsGk/1WLfkDs=; b=iYNwdIwRgttek5i/fgZfAd214TXGYGSGcUC/iYImommEIqlbHVOL1jQdRUNAJgxd2+ BI1udA8e1D+YjnSFFSW6jTH3kVaChGBcY403AjJouyDZKtaWTgNdaTuIMw7HMbY0EMbR 5RO2JmLibM3q5qPcE2QaOawvzBjvV8trr5mZ4+jKPY7tte0lyMVBgx3m5rI4aIm6SzS5 ziWl0+S87FaghMpvZMdRUXAg/1loYVB1BE4Kv/FA1cko5hBMyQFsezUDgOG1+bO8uJhS /sFeG1PIMbxabFcQcR0o/AxALXjL5u2wh4mdjAZ03kaVyCSrS8p018vGqx5m7mjmqIaU J2Bg== MIME-Version: 1.0 X-Received: by 10.66.102.41 with SMTP id fl9mr870045pab.169.1376560450752; Thu, 15 Aug 2013 02:54:10 -0700 (PDT) In-Reply-To: References: <94f8428f-50b9-4ccd-95a0-6eeafda0fe18@googlegroups.com> Date: Thu, 15 Aug 2013 10:54:10 +0100 Subject: Re: .split() Qeustion From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1376560460 news.xs4all.nl 15935 [2001:888:2000:d::a6]:43388 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52545 On Thu, Aug 15, 2013 at 10:46 AM, wrote: > A technical ascpect of triple quoted strings is > that the "end of lines" are not respected. > >>>> import zzz >>>> zzz.__doc__ > 'abc\ndef\n' >>>> with open('zzz.py', 'rb') as fo: > ... r = fo.read() > ... >>>> r > b'"""abc\r\ndef\r\n"""\r\n' > > Now, one can argue... Actually, they are respected. Triple-quoted strings are parsed after the file is read in, and newline handling is dealt with at an earlier level, same as encodings are. You wouldn't expect that string to retain information about the source file's encoding, and nor do you expect it to retain the source file's newline style. A newline is represented in the file on disk as \r\n or \n (or something else, even), and in the string as \n. It's that simple. ChrisA