Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102973

Re: repr( open('/etc/motd', 'rt').read() )

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 <tjreedy@udel.edu>
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 <mailman.147.1455566619.22075.python-list@python.org> (permalink)
References <n9sie9$91s$1@dont-email.me>
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 <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.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 <n9sie9$91s$1@dont-email.me>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21rc2
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:102973

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

repr( open('/etc/motd', 'rt').read() ) "Veek. M" <vek.m1234@gmail.com> - 2016-02-15 18:35 +0530
  Re: repr( open('/etc/motd', 'rt').read() ) Random832 <random832@fastmail.com> - 2016-02-15 09:47 -0500
  Re: repr( open('/etc/motd', 'rt').read() ) Terry Reedy <tjreedy@udel.edu> - 2016-02-15 15:03 -0500
  Re: repr( open('/etc/motd', 'rt').read() ) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-02-16 17:43 +1100

csiph-web