Please help on print string that contains 'tab' and 'newline'
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sun Jan 28 21:04:18 EST 2018
On Sun, 28 Jan 2018 17:49:44 -0800, Dan Stromberg wrote:
> On Sun, Jan 28, 2018 at 5:35 PM, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
>> On Sun, 28 Jan 2018 17:04:56 -0800, Dan Stromberg wrote:
>>> How about:
>>>>>> os.write(1, message)
>>
>> What do you think that will do that print() doesn't do?
>
>>>> message = b'*does not exist\r\n\tat com.*'
>>>> os.write(1, message)
> *does not exist
> at com.*26
>>>> print(message)
> b'*does not exist\r\n\tat com.*'
What was the clue that made you think that Jason was using bytes? In his
posts, he always said it was a string, and when he printed the repr() of
the message, it was a string, not bytes. If it were bytes, we would have
seen this:
py> message = b'*does not exist\r\n\tat com.*'
py> print(repr(message))
b'*does not exist\r\n\tat com.*'
That is NOT the output that Jason showed. His output was:
py> string_message = '*does not exist\r\n\tat com.*'
py> print(repr(string_message))
'*does not exist\r\n\tat com.*'
Ah wait no it wasn't even that. The output he showed had no quotation
marks. I didn't pick up on that: what he sent us as supposed output was
actually impossible. He has been editing the output.
So what was the clue that it was bytes that you saw that (nearly)
everyone else missed? Especially me.
--
Steve
More information about the Python-list
mailing list