English 中文(简体)
甲型六氯环己烷 在单一档案中执行书状和多重档案时,结果不同
原标题:Python os and gob: Different results when executing a script on a single file vs. multiple files
  • 时间:2012-04-26 04:36:41
  •  标签:
  • python

我正在撰写一本有执行功能的选择的长篇剪辑(从2D numpy阵列到数据档案中写出一套手段),涉及单一编外档案或特定目录中的所有.。

例如,

> myscript.py --file=audio.wav --data="data.tab"

应为数据写上浮动点值。

> myscript.py --path="path/with/audio_files" --data="data.tab"

应为数据撰写一套浮动点值。

我有一只双手,有一把西维协会的档案。 当我执行单一档案(有——档案选择)的道路时,结果不同于档案处理后的结果。

我采用了第3号途径:

(1) 使用os(list)

for audioFile in os.listdir(options.path):
    if audioFile.endswith( .wav ):
        foo(audioFile)

2) 使用os。

for r, d, f in os.walk(options.path):
for audioFile in f:
    if audioFile.endswith( .wav ):
            foo(audioFile)  

3) 使用龙虾

for audioFile in glob.glob("*.wav"):
    foo(audioFile)

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.

当我使用斜体或 go模块时,情况会有所不同?

EDIT: Here is where I process all .wav files in a directory:

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)

这一数字为:

# 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) +  	  + str(mfccStdDev) +  	 )

我正在使用YAAFE,从音频文档中提取这些特征。

问题回答

<globFunction do the Unix-types of omitting file whose namestarts with .:

>>> os.listdir( . )
[ conn.c ,  Makefile ,  conn.o ,  .depend ,  conn.c.orig ,  conn ]
>>> glob.glob( * )
[ conn.c ,  Makefile ,  conn.o ,  conn.c.orig ,  conn ]

(note, fnmatch.fnmatch does not do this; the code to skip dot-files is in glob.glob1). Presumably you have some dot-files.

我认为,我解决了这一问题。 问题并不在于我的低温采掘环境,而不是沙捞法。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签