title: Python - defining global name datetime
body: <p>I'm trying to create a function where I use various functions from the datetime module, such as strftime, strptime and timedelta.</p>
  
  <p>I feel like I've tried everything, but every time I am told this: </p>
  
  <pre><code>      4 date = '2012.09.07'
        5 
  ----&gt; 6 q = net(date)
        7 print q
  
  /Users/fb/Documents/Python_files/test_function.pyc in net(date)
        1 def net(date):
  ----&gt; 2     b = datetime.strptime(a, '%Y.%m.%d')
        3     c = b.strftime('%d:%m:%y')
        4     return c
  
  NameError: global name 'datetime' is not defined
  </code></pre>
  
  <p>I've read that others probably experience the same problem as I, namely ' It works in the python interpreter but not in the script'. Can anyone help, please? </p>