我正在尝试使用一个文件中另一个文件中的功能,所以我不需要重复代码。
file.py
def getTrain(data):
trainList = []
for list in data:
for train in list['HorarioDetalhe']:
trainDict = {}
trainDict['id'] = train['ID']
trainDict['origin'] = train['EstacaoOrigem']['Nome']
trainDict['destiny'] = train['EstacaoDestino']['Nome']
trainDict['operator'] = train['Operador']['Nome']
trainDict['status'] = train['EstadoComboio']['Nome']
trainDict['arrivalTime'] = train['HoraChegada']
trainList.append(trainDict)
getDelayedCSV(trainList)
getDeletedCSV(trainList)
我想在另一个文件中使用getDealayedCSV()
和getDeletedCSV()
,因为我想要这两个函数的结果。
答案 0 :(得分:0)
from myfile import getDealayedCSV
或from myfile import getDeletedCSV
。
如果文件名为myfile.py,则只需编写myfile。然后,您可以像调用getDealayedCSV(trainList)
一样正常调用函数