UnboundLocalError: локальная переменная 'flight', на которую ссылаются до назначения - PullRequest
0 голосов
/ 23 октября 2018

Мой код следующий: `

def flight(op, top_users):
    flight_or = "201809"+str(op[5:])+"_"+str(op[:4])
    files = os.listdir("good_data")  # Folder with txt files
    dni_age = {}
    for i in files:
        flight = i[:13]
        if flight == flight_or:
            dni, price, age, sex, flight = good_data_file(i)  # Function that takes information from the txt files
            flight = flight[:13]
            dni_age[dni] = age
    for dni, age in dni_age.items():
        if age < 18:
            print(dni, age," <--- Underage")
        elif dni in top_users.keys():
            print(dni, age," <--- Habitual user  Number of travels:",top_users[dni])
        else:
            print(dni, age)

op = "2892.23"
hab_users = {}  # This is calculated by a function that i'm not naming bc it's too long
flight(op, hab_users)

И я получаю следующую ошибку:

UnboundLocalError: local variable 'flight' referenced before assignment

Я думаю, что программа определяет функцию 'flight' как переменную, ноЯ не знаю почему;какие-нибудь подсказки?

...