Timeline for Python 3: obtain struct.pack output that matches Python 2 struct.pack output
Current License: CC BY-SA 4.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 30, 2020 at 19:15 | vote | accept | duhaime | ||
| May 30, 2020 at 19:15 | comment | added | duhaime | I'm afraid you're right--I think I'll need to change the other internal code to work with bytes. RIP Python 2 πβ°οΈπ | |
| May 30, 2020 at 19:10 | comment | added | tdelaney |
In python 3, strings are unicode characters. I'm not sure how turning bytes or larger binary data (e.g., int), into code points is useful. For instance "\x250" is 'ú' and its utf8 encoding is b'\xc3\xba'. In python 3, strings are not simply byte arrays.
|
|
| May 30, 2020 at 19:04 | comment | added | orlp |
@duhaime That is not a valid string for all values you can give to the struct.pack. You will have to change the other code to work with bytes instead of strings.
|
|
| May 30, 2020 at 19:03 | comment | added | duhaime | I just mean I need this function call to return '\x15', not b'\x15' | |
| May 30, 2020 at 19:02 | comment | added | orlp | @duhaime I don't know what that means. Bytes and strings are quite different. You can try decoding the binary string as UTF-8 perhaps? | |
| May 30, 2020 at 19:00 | comment | added | duhaime |
I cleaned up some of my comments but wanted to ask--this is a bytes data type, whereas Python 2 returns a string--can one get this object as a string type in Python 3? chr(21) returns the string that's needed
|
|
| May 30, 2020 at 18:49 | comment | added | orlp | @duhaime Getting the hexadecimal representation of an integer as a string is a way different question that you originally asked though. | |
| May 30, 2020 at 18:48 | comment | added | orlp |
@duhaime Are you looking for hex(21) or "{:x}".format(21)?
|
|
| May 30, 2020 at 18:46 | comment | added | orlp | @duhaime That's what you wrote, the first byte is 21. Clearly you are looking for something else. | |
| May 30, 2020 at 18:45 | history | answered | orlp | CC BY-SA 4.0 |