Python 函数在特定行后不工作:Pylint表示;“不可检查代码”;
我试图将一个函数应用于多个文件,但我根本无法从该函数获得输出,pylint说代码是不可检查的 这是我当前的代码:Python 函数在特定行后不工作:Pylint表示;“不可检查代码”;,python,pandas,Python,Pandas,我试图将一个函数应用于多个文件,但我根本无法从该函数获得输出,pylint说代码是不可检查的 这是我当前的代码: path = str(askdirectory()) for metric in metrics: corner = pd.read_excel(f'{path}/{metric} - TOP LEFT CELL.xlsx') metricFrame(corner) 到目前为止,代码工作正常,但在函数内部没有任何功能: def metricFrame(corner
path = str(askdirectory())
for metric in metrics:
corner = pd.read_excel(f'{path}/{metric} - TOP LEFT CELL.xlsx')
metricFrame(corner)
到目前为止,代码工作正常,但在函数内部没有任何功能:
def metricFrame(corner,top,left,filling):
# # Extract Top Left Corner Metric from TOP LEFT files
topleft = corner.iloc[0]['A']
return topleft
print(corner) # This is the line that pylint highlights as unreacheable
“返回”导致功能停止运行或中断?为什么会发生这种情况?
return
退出该函数。将print()
语句放在return
之前,将print(角落)
移动到return top left
之前。return
调用结束函数。在return之前粘贴打印是,return
将是函数中执行的最后一条语句。它就是这样做的。return
“返回”函数的值,因此结束它。它永远不会到达代码,pylint在这里的暗示是正确的。翻译将永远无法到达代码print(corner)
,因为您返回的时间早于此。