【发布时间】:2020-11-06 06:48:02
【问题描述】:
我正在尝试跟随project written by Mike Smales - "Sound Classification using Deep Learning"。在那里,作者编写了一个名为 wavfilehelper.py 的帮助文件:
wavehelper.py 代码
import struct
class WavFileHelper():
def read_file_properties(self, filename):
wave_file = open(filename,"rb")
riff = wave_file.read(12)
fmt = wave_file.read(36)
num_channels_string = fmt[10:12]
num_channels = struct.unpack('<H', num_channels_string)[0]
sample_rate_string = fmt[12:16]
sample_rate = struct.unpack("<I",sample_rate_string)[0]
bit_depth_string = fmt[22:24]
bit_depth = struct.unpack("<H",bit_depth_string)[0]
return (num_channels, sample_rate, bit_depth)
在他的主程序中,他这样调用帮助文件:
from helpers.wavfilehelper import WavFileHelper
wavfilehelper = WavFileHelper()
但是,当我在 PyCharm 中运行这段代码时,它会报错“ModuleNotFoundError: No module named 'helpers.wavfilehelper'”...我怎样才能让这个帮助文件在 PyCharm 环境中工作?我是否必须将wavehelper.py 文件放在一个特殊文件夹中才能调用?
任何帮助将不胜感激!
【问题讨论】: