byte string in python2 - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: byte string in python2 (/thread-6430.html) |
byte string in python2 - Skaperen - Nov-22-2017 i want to test something in python2. to do the test i need a byte string. i don't need a byte string type. i only need some way to get a byte string value. RE: byte string in python2 - Larz60+ - Nov-22-2017 you can iterate through the string, and run each character through ord(): example: k = 'kryptonite' ' '.join(format(ord(letter), 'b') for letter in k)result: or for hex:k = 'kryptonite' ' '.join(format(ord(letter), 'x') for letter in k)
RE: byte string in python2 - Skaperen - Nov-22-2017 i mean byte string as in b'foo' where for that value, repr()[0] would == 'b'. but just simply b'foo' doesn't do it. i have see b' stuff come out sometimes in python2 but that was before i switched to doing things in python3 which makes a proper type for this stuff. i'm want to see how some code i wrote behaves when given such a value while running under python2. RE: byte string in python2 - snippsat - Nov-22-2017 bytes objects really only exist in Python 3.x. bytes added in Python 2.6 is an alias to the str type,that only exists to help writing portable code between Python 2 and 3. The Doc for this 2.6: Quote:Python 2.6 adds bytes as a synonym for the str type, and it also supports the b'' notation. RE: byte string in python2 - Skaperen - Nov-23-2017 ok, so the conditions i wanted to test will not actually happen. |