Home > Software engineering >  Import class function variable
Import class function variable

Time:11-17

I'm making a kivy app and I want to import a class function variable to another file. Can anyone help me with this because I can't figure it out. What I want is the following: when the given interval in kivy is equal to 1m it starts the function start_1m as a thread. Now in this start_1m i define an interval which I want to use in the crypto_data.main() file. How do I get this variable in my other file? Below is my code, feel free to ask any questions! Thanks in advance!

class MyFloat(Widget):


    def check_interval(self):
        intervals = []
        if self.check_id_1m.active:
            intervals.append('1m')
        if self.check_id_3m.active:
            intervals.append('3m')
        if self.check_id_5m.active:
            intervals.append('5m')
        if self.check_id_15m.active:
            intervals.append('15m')
        if self.check_id_1d.active:
            intervals.append('1d')
        if self.check_id_3d.active:
            intervals.append('3d')
        if self.check_id_1w.active:
            intervals.append('1w')
        return intervals

    def get_data(self):
        # print(MyFloat.check_interval(self))
        for i in range(len(MyFloat.check_interval(self))):
            if MyFloat.check_interval(self)[i] == '1m':
                print('1m')
                threading.Thread(target=self.start_1m).start()
            if MyFloat.check_interval(self)[i] == '3m':
                print('3m')
            if MyFloat.check_interval(self)[i] == '5m':
                print('5m')
            if MyFloat.check_interval(self)[i] == '15m':
                print('15m')
            if MyFloat.check_interval(self)[i] == '1d':
                print('1d')
            if MyFloat.check_interval(self)[i] == '3d':
                print('3d')
            if MyFloat.check_interval(self)[i] == '1w':
                print('1w')


    def start_1m(self):
        interval = Client.KLINE_INTERVAL_1MINUTE
        crypto_data.main()
        return interval

I tried this by doing the following, but this asks me to input the parameter self. I also tried some other things but I can't get it to work.

from main import MyFloat

def get_interval():
    interval = MyFloat.start_1m()
    return interval

CodePudding user response:

Try making get_interval() into a static method:

@staticmethod
def start_1m():
    interval = Client.KLINE_INTERVAL_1MINUTE
    crypto_data.main()
    return interval
  • Related