Python os and gob: Different results when executing a script on a single file vs. multiple files
<p>I am writing a python shell script that has the option to execute a function (that writes a set of means from a 2D numpy array to a data file) on either a single .wav file or all .wav files in a specified directory.</p>

<p>For example,</p>

<pre><code>&gt; myscript.py --file=audio.wav --data="data.tab"
</code></pre>

<p>should write a floating point value to data.tab.</p>

<pre><code>&gt; myscript.py --path="path/with/audio_files" --data="data.tab"
</code></pre>

<p>should write a set of floating point values to data.tab.</p>

<p>I have a folder with a bunch of WAV files. When I execute the path on a single file (with the --file option), the result is different than the result when file gets processed with the --path option.</p>

<p>I have implemented the path file 3 ways:</p>

<p>1) Using os.listdir()</p>

<pre><code>for audioFile in os.listdir(options.path):
    if audioFile.endswith('.wav'):
        foo(audioFile)
</code></pre>

<p>2) Using os.walk()</p>

<pre><code>for r, d, f in os.walk(options.path):
for audioFile in f:
    if audioFile.endswith('.wav'):
            foo(audioFile)  
</code></pre>

<p>3) Using glob.glob()</p>

<pre><code>for audioFile in glob.glob("*.wav"):
    foo(audioFile)
</code></pre>

<p>Methods 1 and 2 return the same result. Method 3 returns a different result. All 3 methods return a different result than processing a single file.</p>

<p>What is going differently when I use the os or gob modules?</p>

<p>EDIT:
Here is where I process all .wav files in a directory:</p>

<pre><code>for r, d, f in os.walk(options.path): 
    for audioFile in f:
        if audioFile.endswith('.wav'):  
            # Add MFCC 1-12 to data.
            mfcc12(audioFile, sampleRate, data)
</code></pre>

<p>This is in mfcc12():</p>

<pre><code># mfccs is a 2D numpy array. 
# Each column corresponds to one feature of the audiofile
for i in range(mfccs[0].size):
    mfccMean = mfccs[:, i].mean()
    mfccStdDev = mfccs[:, i].std()  
    data.write(str(mfccMean) + '\t' + str(mfccStdDev) + '\t')
</code></pre>

<p>I am using <a href="http://yaafe.sourceforge.net/" rel="nofollow">YAAFE</a> to extract the features from the audio files.</p>
