How Do I Access A Local Folder Through Its Filename?
I have a folder that is my animation/game, and in the folder is the .pyw file and a .wav music file. I have import wave wave.open() and I don't know what to put in the parenthesis
Solution 1:
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)
Post a Comment for "How Do I Access A Local Folder Through Its Filename?"