title: Python Import Module from Decorator
body: <p>I'm working on an application in Python 3, and what I'm doing is unconventional.</p>
  
  <p>cx_Oracle is a difficult module to setup, and for my application is an optional dependency. What I would like to do is wrap the import of the module in a decorator, to place only above the functions that use it. This will keep from having to import at the top of my module and allow it to not be setup.</p>
  
  <pre><code>class Loader():
      def load_cx_oracle(func):
          def inner(*args, **kwargs):
  
              # Additional code before import.
  
              import cx_Oracle
  
              return func(*args, **kwargs)
          return inner
  
      @load_cx_oracle
      def function_using_cx_oracle(self):
          conn = cx_Oracle.connect()
  </code></pre>
  
  <p>However, when I try the above, I get <code>NameError: name 'cx_Oracle' is not defined</code></p>