1
If I want to convert between integers and characters, use chr
and ord
:
>>> chr(10)
'\n'
>>> ord('$')
36
However I need to do a string test binary, something new in Python 3, and I - who only have experience with Python 2 - have no idea how to do it:
# O que eu sei
teste(b'\x00')
teste(b'\x01')
teste(b'\x02')
...
teste(b'\xff')
# O que eu quero
for i in range(256)
teste(???)
I think you are looking for this: http://pythoncentral.io/encoding-and-decoding-strings-in-python-3-x/
– André Ramos
@Andrera This article only talks about the conversion between strings (text) and bytes through a encoding. The problem is those byte sequences that do not represent any text in whichever encoding (ex.:
b"\xdb"
is not a valid string in any Unicode encoding). Anyway, I want to work with "raw" bytes, not text, any such conversion would be a "gambiarra".– mgibsonbr