<p>I have a very tricky situation (for my standards) in hand. I have a script that needs to read a script variable name from <a href="https://docs.python.org/2/library/configparser.html" rel="nofollow noreferrer">ConfigParser</a>. For example, I need to read</p>

<pre><code>self.post.id
</code></pre>

<p>from a .cfg file and use it as a variable in the script. How do I achieve this?</p>

<p>I suppose I was unclear in my query. The .cfg file looks something like:</p>

<pre><code>[head]
test: me
some variable : self.post.id
</code></pre>

<p>This self.post.id is to be replaced at the run time, taking values from the script.</p>

test.ini:
```
```
[head]
var: self.post.id
```
```
python:
```
```
import ConfigParser

class Test:
  def __init__(self):
      self.post = TestPost(5)
  def getPost(self):
      config = ConfigParser.ConfigParser()
      config.read('/path/to/test.ini')
      newvar = config.get('head', 'var')
      print eval(newvar) 

class TestPost:
  def __init__(self, id):
      self.id = id

test = Test()
test.getPost()   # prints 5
```
```