2014-05-15 57 views
-1
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) 

如何使這個代碼pylint的正確嗎?使此代碼pylint的正確

錯誤 - 行太長

+0

請將'self.getHostIP()'後的整個錯誤 – juankysmith

+0

粘貼到下一行(按Enter鍵)。它仍包含在'()'是如此蟒蛇將把它作爲一個單一的代碼行。 – CasualDemon

+0

@CasualDemon什麼關於下一行縮進? ü可以請編寫代碼 – Patrick

回答

4

您可以通過在拆分它多行,用括號內/支架/括號Python的暗示行延續使線條更短:

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

(注意利用對齊要清楚哪些子線永遠在一起)。

另外,行拆分成多個語句:

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

你應該限制在79個字符每PEP-0008

最大線路長度

限制所有線路最多79個字符。

對於流動具有較少結構上的限制(文檔字符串或註釋)文本的長塊中,行的長度應限制於72個字符。

限制所需編輯器窗口的寬度能夠有幾個打開的文件並排側,並利用存在於相鄰列中的兩個版本的代碼審查工具時,效果很好。

2

修復一個「行太長」錯誤的方式 - 使線較短!

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知道該語句在下一行繼續。