Referring on this question, I have a similar -but not the same- problem..
On my way, I\'ll have some text file, structured like:
var_a: \'home\'
var_
What you want appear to want is the following, but this is NOT RECOMMENDED:
>>> for line in open('dangerous.txt'):
... exec('%s = %s' % tuple(line.split(':', 1)))
...
>>> var_a
'home'
This creates somewhat similar behavior to PHP's register_globals and hence has the same security issues. Additionally, the use of exec that I showed allows arbitrary code execution. Only use this if you are absolutely sure that the contents of the text file can be trusted under all circumstances.
You should really consider binding the variables not to the local scope, but to an object, and use a library that parses the file contents such that no code is executed. So: go with any of the other solutions provided here.
(Please note: I added this answer not as a solution, but as an explicit non-solution.)