"Sourcing" a Python file from another
<p>I have a service where users upload egg files. The problem is that a <code>settings.py</code> file needs to be extracted by me and I should only accept some of the values in that file. The file consists of regular Python variables like:</p>

<pre><code>VAR1 = 'Hello'
VAR2 = ['my.list']
VAR3 = {
    'a': 'b'
}
</code></pre>

<p>I need to extract these variables in a good manner and I have looked for a way to 'source' (Bash term I suppose..) the <code>settings.py</code> file to my worker Python file to extract the variables. I haven't found a way to do that when searching. Any ideas?</p>

<p><strong>My (specific) solution</strong></p>

<pre><code># Append path to sys.path
sys.path.insert(0, os.path.dirname('/path/to/settings.py'))

import settings as egg_settings
LOGGER.info('Settings: VAR1 = %s', egg_settings.VAR1)

# Remove from sys.path
sys.path.pop(0)
</code></pre>
