Config python script which knows its filename
<p>I'd like to save complex configuration by writing some Python code with variable assignments and functions which I will import later by a ConfigReader class.</p>

<p>Basically so far I've written my config file:</p>

<pre><code>a=1
</code></pre>

<p>And a class that works like</p>

<pre><code>c=ConfigReader("C:\my_file")
print(c.a)
</code></pre>

<p>For that I used exec(), but now I also want that the config file knows its own filename (since the directory provides information for some variables)</p>

<p>So I need a config file like:</p>

<pre><code>a=parse_project_number_from_dir(__file__)
</code></pre>

<p>It seems I need to replace exec() by some imp module loading in Python 3? Is that the easiest way to execute a simple file making it aware of its path?</p>

<p>Moreover I'd like my ConfigReader class to read all variables into a dictionary. (With exec I just looked at locals() ). What should I do now and can I not import the auxiliary imports in config file (like the parse_project_number_from_dir function), but just what I actually define there (i.e. a=)?</p>
