2011-05-29 124 views
1

文档http://docs.python.org/library/wave.html不可打印字符串数在python

Wave_read.readframes(n) 

读取并返回至多n个帧的音频,以字节为单位的字符串。

我想看看在十六进制或只是许多这样的字符串,知道那么值时没有声音是存在的或加,减音是有

我试图

import wave 

target = wave.open('t2.wav') 

length = target.getnframes() 

section = target.readframes(2205) 

print section[0:2] 

这段代码打印字符串貌似+,当我运行的代码,

print int(section[0:2]) 

引发

Traceback (most recent call last): 

    File "D:/py/pitch2.py", line 5, in <module> 

    print int(section[0:2]) 

ValueError: invalid literal for int() with base 10: '\x10' 

如何解决这个问题?

回答

2
print [ord(i) for i in section[0:2]] 

print [hex(ord(i)) for i in section[0:2]]