In Scapy, I took the first 28 Bytes of a few packets and saved each as a hexadecimal string. Whenever I want to print those strings all together (they are saved in a list), the following happens:
>>> print myStrings[0]
['E\x00\x00W\x00\x00@\x00\x01\x11\xe7-\x8a`t\x86\xd5\x92\xbd\xef0\x1a\xa4\xe8\x00C\xe2k', ['E\x00\x00W\x00\x00@\x00\x01\x11\xe7-\x8a`t\x86\xd5\x92\xbd\xef0\x1a\xa4\xe8\x00C\xe2k']]
But if I want to print each string separately:
>>> for p in tmpStrAns:
... print p[0]
...
EW@�-�`t�Ւ��0��C�k
E8@�L�`t�Ւ��0��$�L
E8@�L�`t�Ւ��0��$�L
(MyStrings is a list of lists: [[string1, [string2,string3,...], ...] )
What’s happening here?
When printing a list, Python calls
list.__str__, which callsrepron each of its items.When printing a string, Python outputs the string directly.
The
reprmethod on strings converts non-printable characters to their hexadecimal representation.