I am trying to access a folder containing 50 .wav file samples (that I will use for my Gender Voice Classification (using PCA) project), but I cant seem to be able to access the folder properly.
The folder is unzipped of course.
the folder containing the file samples is named "SoundSamples", that is inside another folder named "soundFile" that is located on the desktop.
I am running the code below:
import osraw_folder = '//Desktop//soundFile//SoundSamples//'
for file in os.listdir(raw_folder):print(file)filepath = os.path.join(raw_folder, file)f = open(filepath, 'r')print(f.read())f.close()
The output I get is an error saying "no such file or directory: '//Desktop//soundFile//SoundSamples//' "
Answer
You cannot access the relative path to your Desktop folder by starting with the absolute path /Desktop/... As a regular user, your desktop folder is stored somewhere deeper -- typically, something like /Users/(yourname)/Desktop. But don't hardcode that, Python can find the home folder for you!
import os
from os.path import expanduserhome = expanduser("~")
print home
raw_folder = home+'/Desktop/soundFile/SoundSamples'
for file in os.listdir(raw_folder):print(file)
The OS function expanduser locates your home folder and returns it as a string. Then you can paste on whatever folder you are looking for -- Desktop, Documents, or any other path relative to your home.
Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 8…
I have the following code that seeks to read the file contents into a list (this bit works) and then display a message of acceptance, IF the bank details (user and corresponding number) matches. e.g. i…
I want to capture the field or column name that is filtered in the excel file when reading through python. I saw that we can also capture only the filtered rows by using openpyxl and using hidden == Fa…
I am new to python. I am trying to do microphone file that ought to detect, listen, record and write the .wav files. However, it is giving me an error while I am trying to run the file. It is saying:Ty…
So here is a snipit of an IK spine builder Ive been working on. Ive figure out how to make lists to duplicate the bound into an IK chain, what Ive got stuck on however is I want my list and for loop to…
I have the following sample string:R10666: 273141 C1 + 273141 C2 + 273141 C3 + 273141 C4 + 273141 C5 - 273141 C6I want to obtain:[(273141,C1), ..., (- 273141, C6)]The numbers can be floating point numb…
This question already has answers here:How do I print parameters of multiple objects in table form? [duplicate](2 answers)Line up columns of numbers (print output in table format)(7 answers)Closed 5 y…
I have placed a list in a text file. I want python to read the text file and return the contents as a list. However, it is instead reading the content as a string:Text file:[a,b,c]Python:ids=[]writtenF…