How to convert a wav file -> bytes-like object?
问题 I'm trying to programmatically analyse wav files with the audioop module of Python 3.5.1 to get channel, duration, sample rate, volumes etc. however I can find no documentation to describe how to convert a wav file to the 'fragment' parameter which must be a bytes-like object. Can anybody help? 回答1: file.read() returns a bytes object, so if you're just trying to get the contents of a file as bytes , something like the following would suffice: with open(filename, 'rb') as fd: contents = fd