ошибка отсутствует 1 обязательный позиционный аргумент python и поток - PullRequest
0 голосов
/ 28 апреля 2020

Я пытался использовать поток, чтобы получить лучший результат во время выполнения, по некоторым причинам ошибка

Отсутствует 1 обязательный позиционный аргумент: год продолжает появляться на экране

вот функция:

def calculate_the_gain_per_month(self, month, this_year):

self.cur.execute("SELECT following_number FROM data_analysis WHERE month = ? AND year =?", (month, this_year))
result_per_month = self.cur.fetchall()

list_of_following_per_month = []  # list of the following number for each day in the current month
gain_following = []  # list of gain of following per day in the month

for each_day in result_per_month:
   list_of_following_per_month.append(each_day[0])

for index in range(len(list_of_following_per_month) - 1):
                    gain_following.append(list_of_following_per_month[index + 1] - list_of_following_per_month[index])

return gain_following

def calculate_the_gain_per_year(self, year):

threads = [threading.Thread(target=insta_sql.calculate_the_gain_per_month, args=(month,year)) for month in range(12)]

for thread in threads:
  thread.start()

1 Ответ

0 голосов
/ 28 апреля 2020

Не совсем уверен, как выглядит вся ваша конструкция, но следующее должно работать ...

from threading import Thread

class A:

    def __init__(self):
        self.calculate_the_gain_per_year(2000)

    def calculate_the_gain_per_month(self, month, this_year):

                print("SELECT following_number FROM data_analysis WHERE month = {} AND year ={}".format(month, this_year))

                list_of_following_per_month = []  # list of the following number for each day in the current month
                gain_following = []  # list of gain of following per day in the month

                for index in range(len(list_of_following_per_month) - 1):
                    gain_following.append(list_of_following_per_month[index + 1] - list_of_following_per_month[index])

                return gain_following

    def calculate_the_gain_per_year(self, year):

        threads = [Thread(target=self.calculate_the_gain_per_month, args=(month, year)) for month in range(12)]

        for thread in threads:
            thread.start()


a = A()

Конечно, вы также можете вызывать его извне класса, используя объект класса a.calculate_the_gain_per_year(2000).

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...