I am reading a data frame sent by a hardware device that separates each field of the frame with the character '\r'
. When printing the frame in python 2, I have found differences between print
and print()
and some problems with disappearing characters.
Some differences between print()
and print
can be found in:
What is the difference between print and print() in python 2.7
but that not explains the problems that I'm having.
For example, when executing
>>>frame = 'word_1#\rword_2\r'
>>>print(frame)
word_2#
>>>print frame
word_2#
They are both the same, but I don't understand why the '#' is moved to the end of 'word_2' and why 'word_1' disappears.
Also, print
and print()
show different results in:
>>>frame = 'word_1#\rword_2\r'
>>>print('data:', frame)
('data', 'word_1#\rword_2\r')
>>>print 'data:', frame
word_2word_1#
Here print()
seems to work as expected, but print
has removed 'data'
word and has changed the order of the words.
Finally, it is also confusing this case:
>>> frame = 'word_1\r#word2\r#'
>>> print(frame)
#word2
>>> print frame
#word2
>>> print('data', frame)
('data', 'word_1\r#word2\r#')
>>> print 'data', frame
#word2ord_1
where print()
, print
and print('data', frame)
seems to work the same way that they did in the previous cases but print 'data', frame
has removed the initial 'w'
from word_1
after changing the order.
What's happening here?