P
P
Prompt_coder2020-06-03 00:24:56
Python
Prompt_coder, 2020-06-03 00:24:56

How to call a function just once, but also update it constantly?

I have a code where the uniqe_dead_list function returns a certain value every 10 seconds. Also, this function writes the value to a separate file, and it turns out that the next time the function is called (after 10 seconds), it will not add anything if the previous functions do not change their values. But this is not particularly important, the point of my question is whether it is possible to make the function be called only 1 time (every 10 seconds that I have already indicated in the code), and so that the catcher() function will work only with its value, Constantly not calling it (maybe the second time the function is called, it returns completely different values ​​that I need). Initially, I tried to create a variable, but its minus is that the variable does not update its values, and the function updates me every 10 seconds.

def uniqe_dead_list():
    result = list(set(union_deads_func()) - set(dead_last_func()))
    if len(result) != 0:
        my_list = '\n'.join(result)
        deads_last_w = open('logs.txt', 'a', encoding='utf-8')
        deads_last_w.write(f'{my_list}\n')
        deads_last_w.close()
        print('Добавлено')
    print(len(result), '\n'.join(result))
    x = '\n'.join(result)
    return x


def catcher():
    uniqe_dead_list()
    dead_list = (str(uniqe_dead_list()).split('\n'))
    logs_check = open('players_data.txt', 'r', encoding='utf-8')
    checking = logs_check.read()
    logs_check.close()
    dead_users = (checking.split(', ')[:-1])
    users_data = []

    for i in dead_users:
        for e in dead_list:
            if i in e:
                users_data.append(e)
    print(users_data)
    return (users_data)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question