Name error in Python in 'self' definition
<p>Getting <code>Name Error:</code> in python code as shared below. I am a beginner in Python.</p>

<pre><code>from PyQt4 import QtGui, QtCore
import sys
import I2CGenericFrame
import os

class I2CApp(QtGui.QMainWindow, I2CGenericFrame.Ui_winI2CMain):
    def __init__(self):
        super(self.__class__, self).__init__()
        self.setupUi(self)


    self.cmbBusListBox.addItem("Slect ..")
</code></pre>

<p>It is giving following error.</p>

<pre><code>Traceback (most recent call last):
  File "I2cMain.py", line 6, in &lt;module&gt;
    class I2CApp(QtGui.QMainWindow, I2CGenericFrame.Ui_winI2CMain):
  File "I2cMain.py", line 12, in I2CApp
    self.cmbBusListBox.addItem("Slect ..")
NameError: name 'self' is not defined
</code></pre>

<p>Guide me, Thanks in advance.</p>

<p><code>self</code> is an argument like any other that is passed in a method. It has no meaning in the class body outside of a method.</p>

<p>You can resolve this by fixing the indentation so that it is referenced inside the <code>__init__</code> method:</p>

<pre><code>class I2CApp(QtGui.QMainWindow, I2CGenericFrame.Ui_winI2CMain):
    def __init__(self):
        super(I2CApp, self).__init__()
        self.setupUi(self)
        self.cmbBusListBox.addItem("Slect ..")
</code></pre>

<p>EDIT: As indicated in the comment, you should also call <code>super</code> with the class explicitly, to avoid the possibility of infinite recursion.</p>

python linux