I am using the ConfigParser
module in Python 2.6 and I wish to load formatted strings from my configuration file. An example of such a string might be the following:
[Section Name]
#in the config file
#tmp_string has value 'string'
my_string = 'This is a %s' % tmp_string
Is there a nice way to save such strings in the config file? I am not going to know what the value of the string is until I load the config file, so I can't evaluate it and then save it to the file or anything like that. Obviously at the moment, when I load the string and print it out, I get the following:
#config is the ConfigParser
my_string = config.get('Section Name', 'my_string')
print my_string
>>>'This is a %s' % tmp_string
I would love to get the output:
>>> This is a string
How do you achieve this? I would preferably like to stay with ConfigParser
, but another option may be acceptable. (I know you can't just print the string and have it magically appear how you would like it to, I am just trying to demonstrate what I wish to do.)