Lucas Lucas - 3 months ago 12
Python Question

How to read config from string or list?

Is it possible to read the configuration for

ConfigParser
from a string or list?

Without any kind of temporary file on a filesystem

OR

Is there any similar solution for this?

Answer

You could use a buffer which behaves like a file:

import ConfigParser
import StringIO

s_config = """
[example]
is_real: False
"""
buf = StringIO.StringIO(s_config)
config = ConfigParser.ConfigParser()
config.readfp(buf)
print config.getboolean('example', 'is_real')