0

我已经坐了几个小时,但我仍然无法完全解决这里的错误。我想打开一个文件并在函数'function_names'中使用它,但是,无论出于何种原因,我似乎都做不到。

这是我的代码。

def function_names (file_name):        
    openn = open(file_name, 'r')        
    array_form = openn.readlines()    
    length_array = (len(array_form) - 1)        
    count = 0        
    new_array = [];        
    result = " "        
    while (count <= length_array):            
        point = array_form [count]            
        point = str(point)            
        search =point.rfind('def')            
        end = point.rfind('(')            
        if (search != -1):                
            result = point[4:end]                
            new_array.insert(count, result)             
    count = count + 1        
    return (new_array)    
x = function_names('ex4.py')    
print (x)
4

0 回答 0