repr( open('/etc/motd', 'rt').read() )
Veek. M
vek.m1234 at gmail.com
Mon Feb 15 08:05:01 EST 2016
When I do at the interpreter prompt,
repr( open('/etc/motd', 'rt').read() )
i get # 1 #:
"'\\nThe programs included with the Debian GNU/Linux system are free
software;\\nthe exact distribution terms for each program are described
in the\\nindividual files in /usr/share/doc/*/copyright.\\n\\nDebian
GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent\\npermitted
by applicable law.\\n'"
whereas if i just do:
open('/etc/motd', 'rt').read()
i get # 2 #:
'\nThe programs included with the Debian GNU/Linux system are free
software;\nthe exact distribution terms for each program are described
in the\nindividual files in /usr/share/doc/*/copyright.\n\nDebian
GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent\npermitted by
applicable law.\n'
---------------
With # 2 # read returns a string that the interpreter displays by
calling __str__ via print so newlines are converted to \n.
What is happening with # 1 # (repr)?
repr calls __repr__ which gives you bytes.. why does this result in \\n
More information about the Python-list
mailing list