title: Python NameError when attempting to use a user-defined class
body: <p>I'm getting a weird instance of a NameError when attempting to use a class I wrote.  In a directory, I have the following file structure:</p>
  
  <ul>
  <li>dir/    
  
  <ul>
  <li>ReutersParser.py</li>
  <li>test.py</li>
  <li>reut-xxx.sgm</li>
  </ul></li>
  </ul>
  
  <p>Where my custom class is defined in ReutersParser.py and I have a test script defined in test.py.</p>
  
  <p>The ReutersParser looks something like this:</p>
  
  <pre><code>from sgmllib import SGMLParser
  
  class ReutersParser(SGMLParser):
  
      def __init__(self, verbose=0):
          SGMLParser.__init__(self, verbose)
  
      ... rest of parser
  
  if __name__ == '__main__':
  
      f = open('reut2-short.sgm')
      s = f.read()
  
      p = ReutersParser()
      p.parse(s)
  </code></pre>
  
  <p>It's a parser to deal with SGML files of Reuters articles.  The test works perfectly.  Anyway, I'm going to use it in test.py, which looks like this:</p>
  
  <pre><code>from ReutersParser import ReutersParser
  
  def main():
      parser = ReutersParser()
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>When it gets to that parser line, I'm getting this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "D:\Projects\Reuters\test.py", line 34, in &lt;module&gt;
      main()
    File "D:\Projects\Reuters\test.py", line 19, in main
      parser = ReutersParser()
    File "D:\Projects\Reuters\ReutersParser.py", line 38, in __init__
      SGMLParser.__init__(self, verbose)
  NameError: global name 'sgmllib' is not defined
  </code></pre>
  
  <p>For some reason, when I try to use my ReutersParser in test.py, it throws an error that says it cannot find sgmllib, which is a built-in module.  I'm at my wits' end trying to figure out why the import won't work.</p>
  
  <p>What's causing this NameError? I've tried importing sgmllib in my test.py and that works, so I don't understand why it can't find it when trying to run the constructor for my ReutersParser.</p>