title: using import inside class
body: <p>I am completely new to the python class concept. After searching for a solution for some days, I hope I will get help here:</p>
  
  <p>I want a python class where I import a function and use it there. The main code should be able to call the function from the class. for that I have two files in the same folder.</p>
  
  <hr>
  
  <p>Thanks to @cdarke, @DeepSpace and @MosesKoledoye, I edited the mistake, but sadly that wasn't it.</p>
  
  <p>I still get the Error:</p>
  
  <pre class="lang-none prettyprint-override"><code>test 0
  Traceback (most recent call last):
    File "run.py", line 3, in &lt;module&gt;
      foo.doit()
    File "/Users/ls/Documents/Entwicklung/RaspberryPi/test/test.py", line 8, in doit
      self.timer(5)
    File "/Users/ls/Documents/Entwicklung/RaspberryPi/test/test.py", line 6, in timer
      zeit.sleep(2)
  NameError: global name 'zeit' is not defined
  </code></pre>
  
  <hr>
  
  <hr>
  
  <p>@wombatz got the right tip: 
  it must be self.zeit.sleep(2) or Test.zeit.sleep(2). the import could be also done above the class declaration. </p>
  
  <hr>
  
  <p><strong>Test.Py</strong></p>
  
  <pre><code>class Test:
      import time as zeit
      def timer(self, count):
          for i in range(count):
              print("test "+str(i))
              self.zeit.sleep(2)      &lt;-- self is importent, otherwise, move the import above the class declaration
      def doit(self):
          self.timer(5)
  </code></pre>
  
  <p>and</p>
  
  <p><strong>run.py</strong></p>
  
  <pre><code>from test import Test
  foo = Test()
  foo.doit()
  </code></pre>
  
  <p>when I try to <code>python run.py</code> I get this error:</p>
  
  <pre class="lang-none prettyprint-override"><code>test 0
  Traceback (most recent call last):
    File "run.py", line 3, in &lt;module&gt;
      foo.doit()
    File "/Users/ls/Documents/Entwicklung/RaspberryPi/test/test.py", line 8, in doit
      self.timer(5)
    File "/Users/ls/Documents/Entwicklung/RaspberryPi/test/test.py", line 6, in timer
      sleep(2)
  NameError: global name 'sleep' is not defined
  </code></pre>
  
  <p>What I understand from the error is that the import in the class is not recognized. But how can I achive that the import in the class is recognized?</p>