'Pickle in python3, error on concating string to bytes

I am converting some code from python2 to 3 and saw an error that the 2to3 did not catch on a line:

pickle.dumps(('predskew', predskewData[0])) + pickleSep

That produces an error in python3:

pickledPredskewData = pickle.dumps(('predskew', predskewData[0])) + pickleSep

TypeError: can't concat str to bytes

I know from other posts on stack over flow I could perhaps use an encode? or a decode? I just wasn't sure where or what. So I did try this in python2:

pickleSep = ":::::"
pickle.dumps(('predskew',0)) + pickleSep

Which produces:

"(S'predskew'\np0\nI0\ntp1\n.:::::"

Also,

pickle.dumps(('predskew',0)) + pickleSep.encode()

Gives the same result.

Now if I try the same line in python3, I get what 'looks' like vastly different output:

pickle.dumps(('predskew', 0)) + pickleSep.encode()

Gives the output of:

b'\x80\x04\x95\x10\x00\x00\x00\x00\x00\x00\x00\x8c\x08predskew\x94K\x00\x86\x94.:::::'

So not sure my encode fix is the right approach as the answers seem different (unless it is the print just showing me the bytes itself?!)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source