Lucas Lucas - 1 year ago 125
Python Question

How to read config from string or list?

Is it possible to read the configuration for

from a string or list?

Without any kind of temporary file on a filesystem


Is there any similar solution for this?

Answer Source

You could use a buffer which behaves like a file:

import ConfigParser
import StringIO

s_config = """
is_real: False
buf = StringIO.StringIO(s_config)
config = ConfigParser.ConfigParser()
print config.getboolean('example', 'is_real')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download