开发者

Error when defining python class (threading)

开发者 https://www.devze.com 2023-03-14 10:42 出处:网络
class Downloader(threading.Thread): def __init__(self, priority_level, output_function): self.IDs = self.load_IDs(priority_level)
class Downloader(threading.Thread):
    def __init__(self, priority_level, output_function):
        self.IDs = self.load_IDs(priority_level)
        self.sleep_interval = self.gen_sleep(priority_level)
        self.output = output_function
        self.name = '[Downloader::%s]'%(str(priority_level))

        self.output('[Downloader] New downloader created (prio: %s)!'%(str(priority_level))

    def load_IDs(self, prio):
        filename = 'id_prio%s.data'%str(prio)
        ID_file = open(filename, 'r')
        ID_data = ID_file.read()
        ID_file.close()

        temp = open(filename, 'w')
        temp.write('\n')
        temp.close()

        IDs = [line.split(':') for line in ID_data.split('\n') if ID != '']

        return IDs

[MORE CODE...]

For some reason, I get the following error:

  File "pastebin_rip_2.py", line 40
    def load_IDs(self, prio):
      ^
SyntaxError: invalid syntax

What am I doing wrong? for a moment I considered the issue might have been the placing of init, because when I moved it to 开发者_如何学Gothe end of the Downloader class it worked fine (which doesn't make sense?). Well, Downloader did, anyway. Instead I got a message complaining about the class after Downloader.

I really don't see what's wrong. Help?

(Entire code: http://snipt.org/xkky)


I think you're missing a closing paren at this line:

self.output('[Downloader] New downloader created (prio: %s)!'%(str(priority_level))
0

精彩评论

暂无评论...
验证码 换一张
取 消