Path: csiph.com!2.eu.feeder.erje.net!feeder.erje.net!1.eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!not-for-mail From: Terry Reedy Newsgroups: comp.lang.python Subject: Re: repr( open('/etc/motd', 'rt').read() ) Date: Mon, 15 Feb 2016 15:03:21 -0500 Lines: 67 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de ocnpCjbIcy+dRadEnEyj/QdboAr7li8386VabQwBGp8Q== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'newline': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'repr': 0.09; 'jan': 0.11; 'question.': 0.13; 'interpreter': 0.15; "'at": 0.16; 'duplicates': 0.16; 'elsewhere,': 0.16; 'essential,': 0.16; 'illustrates': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'wrote:': 0.16; 'string': 0.17; 'case.': 0.18; 'result,': 0.18; '>>>': 0.20; 'complete,': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'question': 0.27; 'said,': 0.27; 'idea': 0.28; 'prints': 0.29; 'subject:/': 0.30; 'post': 0.31; 'posting': 0.32; 'idle': 0.33; 'open': 0.33; 'case,': 0.34; 'add': 0.34; 'question,': 0.35; 'should': 0.36; 'received:71': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'received:org': 0.37; 'skip:p 20': 0.38; 'end': 0.39; 'to:addr:python.org': 0.40; 'questions': 0.40; 'your': 0.60; 'behavior': 0.61; 'leaving': 0.63; 'here': 0.66; 'prompt': 0.79; '3.5.1': 0.84; 'demonstrates': 0.84; 'subject:( ': 0.84; 'collective': 0.91; 'received:fios.verizon.net': 0.91; 'responses': 0.93 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: pool-71-185-227-36.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21rc2 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:102973 On 2/15/2016 8:05 AM, Veek. M wrote: > When I do at the interpreter prompt, > repr( open('/etc/motd', 'rt').read() ) > i get # 1 #: When posting questions here or at Stackoverflow or elsewhere, it is a really good idea to develop and post a 'minimal, complete, verifiable example' that demonstrates the behavior in question. In this case, the open and read calls are just noise. A string with a newline illustrates your question without distraction. >>> s = '\n' >>> len(s) 1 >>> len(str(s)) 1 >>> len(repr(s)) 4 >>> s '\n' >>> str(s) '\n' >>> repr(s) "'\\n'" >>> print(s) >>> print(str(s)) >>> print(repr(s)) '\n' >>> For this question, 'at the interpreter prompt' is essential, so leaving the >>> prompt is a good idea. I did the above with 3.5.1 also in IDLE and got exactly the same result, which should be the case. print('start') s='\n' print(s) print(str(s)) print(repr(s)) print('add repr') print(repr(s)) print(repr(str(s))) print(repr(repr(s))) print('end') duplicates the collective >>> responses seen above and demonstrates, as Random832 said, that '>>> expr' prints repr(expr). start '\n' add repr '\n' '\n' "'\\n'" end -- Terry Jan Reedy