title: NameError: name 'MyClass' is not defined
body: <p>I have written a small piece of code in Python, I was trying to run the code from the command line as follows</p>
  
  <blockquote>
    <p>python -c MyClass.py </p>
  </blockquote>
  
  <p>The contents of MyClass.py are as follows:</p>
  
  <pre><code>#!/usr/bin/python
  import logging;
  
  class MyClass():
      data = None
      logger = logging.getLogger(__name__)
  
  def __init__(self, data):
      self.data   = data
  
  if __name__ == "__main__":
      a = MyClass("Data")
      a.logger.info("This is message")
  </code></pre>
  
  <p>The above code fails with the following error</p>
  
  <pre><code>Traceback (most recent call last):
  File "&lt;string&gt;", line 1, in &lt;module&gt;
  NameError: name 'MyClass' is not defined
  </code></pre>
  
  <p>Mind you, when I ran this from the python tool, IDLE, I saw no issues and the code ran as expected, I am confused as to what I am missing. Also, I saw several variants of this question, but the problem I am facing is specific to me,so , please help me.</p>