Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top