title: Python: "global name 'time' is not defined"
body: <p>I'm writing a silly program in python for a friend that prints "We are the knights who say 'Ni'!". then sleeps for 3 seconds, and then prints "Ni!" twenty times at random intervals using the <code>random</code> module's <code>uniform()</code> method. Here's my code:</p>
  
  <pre><code>from time import sleep
  import random
  
  def knights_of_ni():
      generator = random.Random()
      print "We are the knights who say 'ni'."
      sleep(3)
      for i in range(0,20):
          print "Ni!"
          sleep(generator.uniform(0,2))
  </code></pre>
  
  <p>I've tried to import this module by typing in the interpreter <code>from silly import knights_of_ni()</code> <em>and</em> <code>import silly</code>, then calling the function  with either <code>knights_of_ni()</code> or <code>silly.knights_of_ni()</code> (respectively), but I always get the same exception:</p>
  
  <pre><code> NameError: global name 'time' is not defined
  </code></pre>
  
  <p>What is causing this error and how can I fix my code?</p>
  
  <p>Edit: quite frankly, I'm not sure what problem I was having either. I ran the code the next morning and it worked just fine. I swear that the code produced errors last night... Anyway, thanks for your insight.</p>