How To Print Values Of A String Full Of "chaos Question Marks"
Solution 1:
To be clear, your audio data is a byte string. The byte string is a representation of the bytes stored in the audio file. You are not going to simply be able to convert those bytes into meaningful values without knowing what is in the binary first.
As an example, the mp3 specification says that each mp3 contains header frames (described here: http://en.wikipedia.org/wiki/MP3). To read the header you would either need to use something like bitstring, or if you feel comfortable doing the bitwise manipulation yourself then you would just need to unpack an integer (4 bytes) and do some math to figure out the values of the 32 individual bits.
It really all depends on what you are trying to read, and how the data was generated. If you have whole byte numbers, then struct will serve you well.
Solution 2:
If you're ok with the \xd1
mentioned above:
for item in data: printrepr(item),
Note that for x in data
will iterate over each value in the list rather than its location. If you want the location you can use for i in range(len(data)): ...
If you want them in numerical form, replace repr(item)
with ord(item)
.
Solution 3:
It is better if you use the new {}.format
method:
data = "����������������"
print '{0}'.format(data[3])
Solution 4:
You could use ord
to map each byte to its numeric value between 0-255:
printmap(ord, data)
Or, for Python 3 compatibility, do:
print([ord(c) for c in data])
It will also work with Unicode glyphs, which might not be what you want, so make sure you have a bytearray or an actual str
or bytes
object in Python 2.
Post a Comment for "How To Print Values Of A String Full Of "chaos Question Marks""