-1

I am trying to use a function from one file in another one so i dont need to be repeating the code.

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)

i want to use the getDealayedCSV() and getDeletedCSV() in another file since i want the result of these 2 functions.

shuberman
  • 1,416
  • 6
  • 21
  • 38
Bruno Teixeira
  • 128
  • 1
  • 12

1 Answers1

0

from myfile import getDealayedCSV or from myfile import getDeletedCSV .

If your file name is myfile.py you just have to write myfile .Then you can call your function normally like getDealayedCSV(trainList)

Kartikeya Sharma
  • 1,335
  • 1
  • 10
  • 22