r/badcode • • Feb 16 '21

[deleted by user]

[removed]

32 Upvotes

77 comments sorted by

View all comments

Show parent comment

1

u/shiningmatcha Feb 21 '21

I found the doc too brief. That’s why I asked. I only know Python. The doc says the method “Return a bytes object containing the values v1, v2, ...”. How is a bytes object different from a string?

1

u/Tyulis Feb 21 '21 edited Feb 21 '21

A bytes object in python is just a string of bytes, not encoded like a str is. So struct helps to pack values as raw bytes — for example, on my code above (please don’t learn from it ^^"), it packs integer values into 4 bytes each