Python | TypeError:“NoneType”对象不是callab

2024-04-29 16:20:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用以下代码从音频文件中提取一些功能,并将它们写入numpy数组文件中: 在

def calc_ceps(file_list, index, label, method=None, n_mfcc=None, s_rate=None):    
    '''Calculates and saves ceps'''

    if method == None:
        method = 'librosa'
    if s_rate == None:
        s_rate = 22050
    if n_mfcc == None:
        n_mfcc = 20    

    print 'Wave to Ceps:'
    total = len(file_list)    

    for i, file in enumerate(file_list):         

        if method == 'librosa':
            ceps = np.array(librosa.feature.mfcc(*read_wave(file), n_mfcc=n_mfcc))
            ceps.shape = (len(ceps[0]), n_mfcc)

        elif method == 'talkbox':
            ceps = mfcc(read_wave(file)[0])[0]

        write_data('ceps', ceps, label[i], file)
        progress(i, total)  

    progress(199, 199)

函数progress(current,total)打印进度,file_popul()提供文件列表,write峈data()将numpy数组写入文件。在

呼叫:

^{pr2}$

calc ceps()函数100%按预期工作(即为它获得的所有文件保存numy数组),当它结束(即写入所有文件)时,我得到以下回溯:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable

带步骤的pdb输出:

>>> calc_ceps(*file_popul())()    
Wave to Ceps:
99%> ~/final_project/code/utilities.py(122)calc_ceps()
-> progress(199, 199)
(Pdb) s
--Call--
> ~/python/final_project/code/utilities.py(16)progress()
-> def progress(current, maximum):
(Pdb) s
> ~/python/final_project/code/utilities.py(18)progress()
-> ratio = round((float(current) / float(maximum)), 2) * 100
(Pdb) s
> ~/python/final_project/code/utilities.py(19)progress()
-> if ratio < 100:
(Pdb) s
> ~/python/final_project/code/utilities.py(22)progress()
-> elif ratio == 100:
(Pdb) s
> ~/python/final_project/code/utilities.py(23)progress()
-> sys.stdout.write("\r100%  done! \n")
(Pdb) s
100%  done! 
--Return--
> ~/python/final_project/code/utilities.py(23)progress()->None
->sys.stdout.write("\r100%  done! \n")
(Pdb) s
--Return--
> ~/python/final_project/code/utilities.py(122)calc_ceps()->None
-> progress(199, 199)
(Pdb) s
TypeError: "'NoneType' object is not callable"
> <stdin>(1)<module>()
(Pdb) s
--Return--
> <stdin>(1)<module>()->None
(Pdb) s
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable
>>> 

使用Python2.7

提前谢谢。在

编辑:注释掉了progress()用法,这是我在pdb中得到的:

>>> calc_ceps(*file_enum())()
Wave to Ceps:
--Return--
> /home/mpir/python/final_project/code/utilities.py(121)calc_ceps()->None
-> import pdb; pdb.set_trace()
(Pdb) s
TypeError: "'NoneType' object is not callable"
> <stdin>(1)<module>()
(Pdb) s
--Return--
> <stdin>(1)<module>()->None
(Pdb) s
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable
>>> 

奇怪吗?在


Tags: 文件pyprojectnonestdincodecalcpdb