做这个密码塔

2024-10-03 23:20:41 发布

您现在位置:Python中文网/ 问答频道 /正文

def scanDevices(self):
    """ Start 2 threads, one for scanning devices and other for displaying device list on UI
    """
    self.counter = self.counter + 1
    deviceListChangedEvent = threading.Event()
    threadToScanDevices = threading.Thread(target=test_ssdp.main, args=(self.getHostIP(), self.counter, deviceListChangedEvent,))
    threadToScanDevices.setDaemon(True)
    threadToScanDevices.start()
    threadToDisplayDevices = threading.Thread(target=self.displayDevices, args=(deviceListChangedEvent,))
    threadToDisplayDevices.setDaemon(True)
    threadToDisplayDevices.start()
    self.scan.setEnabled(False)
    self.cw.btnPushProfile.setEnabled(False)

如何使这个密码正确?在

错误-行太长


Tags: selffalsetruetargetforcounterargsthread
2条回答

您可以通过将行拆分为多行,使用Python在圆括号/方括号/大括号中的隐式行延续来缩短行:

threadToScanDevices = threading.Thread(target=test_ssdp.main, 
                                       args=(self.getHostIP(), 
                                             self.counter, 
                                             deviceListChangedEvent,))

(注意对齐的使用,以明确哪些子线属于一起)。在

或者,将行拆分为多个语句:

^{pr2}$

每个PEP-0008应限制为79个字符:

Maximum line length

Limit all lines to a maximum of 79 characters.

For flowing long blocks of text with fewer structural restrictions (docstrings or comments), the line length should be limited to 72 characters.

Limiting the required editor window width makes it possible to have several files open side-by-side, and works well when using code review tools that present the two versions in adjacent columns.

修正“线条过长”错误的方法是-缩短线条!在

def scanDevices(self):
    """ Start 2 threads, one for scanning devices and other
        for displaying device list on UI
    """
    self.counter = self.counter + 1
    deviceListChangedEvent = threading.Event()
    threadToScanDevices = threading.Thread(target=test_ssdp.main,
                                           args=(self.getHostIP(),
                                           self.counter,
                                           deviceListChangedEvent,))
    # etc

由于该行在括号内被打断,Python知道该语句在下一行继续。在

相关问题 更多 >