title: How to import a Python module into a local variable using an arbitrary path?
body: <p>I'm trying to use a python file as a config file.  In my real program, I let the user specify the config file at the command line.</p>
  
  <p>Here's my example:</p>
  
  <p><code>some_randomly_named_file.py</code>:</p>
  
  <pre><code>import os
  from datetime import timedelta
  
  PROJECT = "my project"
  ENABLED_FORMATS = ['xml', 'json', 'yaml']
  EXPIRATION=3600
  
  #DEBUG = True
  #TESTING = False
  
  LOG_FOLDER = os.path.join(os.path.expanduser('~'), 'logs')
  </code></pre>
  
  <p>The file is stored here: <code>/foo/bar/baz/some_randomly_named_file.py</code></p>
  
  <p>...and then in <code>myapp.py</code>:</p>
  
  <pre><code># parse the command line and get the path
  path_to_file = '/foo/bar/baz/some_randomly_named_file.py'
  
  # load the python file at path_to_file into local variable myconfig
  # [What do I write here to accomplish this?]
  
  # And now we have a local variable called myconfig
  print(myconfig.PROJECT)
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>my project
  </code></pre>