更新时间:2022-04-16 08:48:42
常用的方法是使用当前模块的路径(该路径在预定义的__file__
变量中自动可用)来确定到子目录中的文件:
A common way this is done is by using the path of the current module, which is automatically available in the predefined__file__
variable, to determine the path to the file in the subdirectory:
import os
import wave
mydir = os.path.dirname(__file__)
subdir = 'sounds'
wavefilepath = os.path.join(mydir, subdir, 'Music.wav')
wave.open(wavefilepath)