我想从WAV文件返回索引位置。返回索引文件内容的位置
如果发现干草堆中的针头内容,那么我需要返回大海捞针中的针头索引位置。
haystack = open("haystack.wav",'r').read()
needle = open("needle.wav",'r').read()
print(haystack.index(needle[:46]));
我得到一个错误:
Traceback (most recent call last):
File "test.py", line 1, in <module>
haystack = open("haystack.wav",'r').read()
File "C:\Python33\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 5: character maps to <undefined>
它的工作我做这在PHP中时:
您正在以文本形式阅读文件。你应该将它作为带有'rb'模式的字节读取。 (但是'index'不能按预期工作。) – Ryan 2013-02-28 17:52:01
那么像我在PHP中所做的解决方案是什么?它的工作。 – 2013-02-28 17:52:29