문제

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)

How to make this code pylint correct ?

error - line too long

도움이 되었습니까?

해결책

You can make the line shorter by splitting it over multiple lines, using Python's implicit line continuation inside parentheses/brackets/braces:

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

(Note the use of alignment to make it clear which sub-lines belong together).

Alternatively, split the line into more than one statement:

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

You should limit to 79 characters per PEP-0008:

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.

다른 팁

The way to fix a "line too long" error is - make the line shorter!

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

Because the line is broken inside parentheses, Python knows that the statement is continued on the next line.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top