title: PyQt - setText method of QTableWidget gets AttributeError
body: <p>I used pyuic to compile a GUI file from Qt Designer, and I tried to figure out how to set all the cells in the first column with the same value <code>"n"</code>.</p>
  
  <p>The following is my code:</p>
  
  <pre><code>class Ui_MainWindow(object):
      ...
      def accinit(self):
          for n in xrange(9):
              item = self.tableWidget.item(n, 0)
              item.setText(_translate("MainWindow", "n", None))
  </code></pre>
  
  <p>Console ouput:</p>
  
  <blockquote>
    <p>AttributeError: 'NoneType' object has no attribute 'setText'</p>
  </blockquote>
  
  <p>I changed the code for only one cell (0,0), and it works perfectly:</p>
  
  <pre><code>def accinit(self):
      item = self.tableWidget.item(0, 0)
      item.setText(_translate("MainWindow", "n", None))
  </code></pre>
  
  <p>The cell at (0,0) has content <code>"n"</code>.</p>
  
  <p>I thought maybe that it's not allowed in a for loop, so I changed code to:</p>
  
  <pre><code>def accinit(self):
      for x in xrange(1):
          item = self.tableWidget.item(0, 0)
          item.setText(_translate("MainWindow", "n", None))
  </code></pre>
  
  <p>But it still works! Why?</p>
  
  <p>I already referenced the following articles (but I still can't solve this error):</p>
  
  <p><a href="https://stackoverflow.com/questions/8949252/python-attribute-error-nonetype-object-has-no-attribute-something">Python: Attribute Error - 'NoneType' object has no attribute 'something'</a></p>
  
  <p><a href="https://stackoverflow.com/questions/24972779/python-attributeerror-nonetype-object-has-no-attribute-close">Python AttributeError: NoneType object has no attribute 'close'</a></p>