PyDocs

Nav

File Formats

ConfigParser.read_string

configparser

method of ConfigParser · Added in 3.2 (source)
  • ConfigParser.read_string(string, source='<string>')
Read configuration from a given string.
1 Example
>>> import configparser

>>> sample_config = """
... [mysqld]
...   user = mysql
...   pid-file = /var/run/mysqld/mysqld.pid
...   skip-external-locking
...   old_passwords = 1
...   skip-bdb
...   # we don't need ACID today
...   skip-innodb
... """
>>> config = configparser.ConfigParser(allow_no_value=True)
>>> config.read_string(sample_config)

>>> # Settings with values are treated as before:
>>> config["mysqld"]["user"]
'mysql'

>>> # Settings without values provide None:
>>> config["mysqld"]["skip-bdb"]

>>> # Settings which aren't specified still raise an error:
>>> config["mysqld"]["does-not-exist"]
Traceback (most recent call last):
  ...
KeyError: 'does-not-exist'
from the Python docs
See Also
No see-alsos for configparser/ConfigParser.read_string
0 Notes
No notes for ConfigParser.read_string