Linked Questions

Popular Questions

Python: __init__ in a class

Asked by At

I have a file called main.py,it call other .py file like Auth.py.
In main.py,I have a repeat loop,It call work function in other py.
But I found that once it call the function,the __init__ will be run once.
I only need it to run the __init__ when it import.How can I achieve that?

main.py

from Auth import Auth
from Group import Group
from SliverBox import SilverBox
from Task import Task

while (1):
    Auth().work()
    Group().work()
    SilverBox().work()
    Task().work()

Auth.py

import json
import time
import base64
import requests
from Log import Log
from Curl import Curl
from config import config
from Base import openssl_public_encrypt,arrange_cookie

class Auth():

    def __init__(self):
        self.lock = int(time.time())

    def work(self):
        if self.lock > int(time.time()):
            return

        if config["Token"]["ACCESS_TOKEN"] == "":
            self.loginPassword()
        else:
            self.loginToken()

        self.checkCookie()

        self.lock = int(time.time()) +3600

Related Questions