Is it possible to unpack a tuple in Python without creating unwanted variables?

后端 未结 4 913
甜味超标
甜味超标 2020-12-29 02:21

Is there a way to write the following function so that my IDE doesn\'t complain that column is an unused variable?

def get_selected_index(self):
           


        
4条回答
  •  自闭症患者
    2020-12-29 03:07

    In Python the _ is often used as an ignored placeholder.

    (path, _) = self._treeView.get_cursor()
    

    You could also avoid unpacking as a tuple is indexable.

    def get_selected_index(self):
        return self._treeView.get_cursor()[0][0]
    

提交回复
热议问题