diff options
author | Georg Brandl <georg@python.org> | 2008-02-01 11:56:49 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2008-02-01 11:56:49 (GMT) |
commit | f69451833191454bfef75804c2654dc37e8f3e93 (patch) | |
tree | 7e81560f5276c35f68b7b02e75feb9221a82ae5d /Doc/library/configparser.rst | |
parent | f25ef50549d9f2bcb6294fe61a9902490728edcc (diff) | |
download | cpython-f69451833191454bfef75804c2654dc37e8f3e93.zip cpython-f69451833191454bfef75804c2654dc37e8f3e93.tar.gz cpython-f69451833191454bfef75804c2654dc37e8f3e93.tar.bz2 |
Update docs w.r.t. PEP 3100 changes -- patch for GHOP by Dan Finnie.
Diffstat (limited to 'Doc/library/configparser.rst')
-rw-r--r-- | Doc/library/configparser.rst | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst index 28f2e59..89bd441 100644 --- a/Doc/library/configparser.rst +++ b/Doc/library/configparser.rst @@ -199,7 +199,7 @@ RawConfigParser Objects .. method:: RawConfigParser.read(filenames) Attempt to read and parse a list of filenames, returning a list of filenames - which were successfully parsed. If *filenames* is a string or Unicode string, + which were successfully parsed. If *filenames* is a string, it is treated as a single filename. If a file named in *filenames* cannot be opened, that file will be ignored. This is designed so that you can specify a list of potential configuration file locations (for example, the current @@ -330,8 +330,8 @@ The :class:`SafeConfigParser` class implements the same extended interface as .. method:: SafeConfigParser.set(section, option, value) If the given section exists, set the given option to the specified value; - otherwise raise :exc:`NoSectionError`. *value* must be a string (:class:`str` - or :class:`unicode`); if not, :exc:`TypeError` is raised. + otherwise raise :exc:`NoSectionError`. *value* must be a string; if it is + not, :exc:`TypeError` is raised. Examples @@ -373,12 +373,12 @@ An example of reading the configuration file again:: # getint() and getboolean() also do this for their respective types float = config.getfloat('Section1', 'float') int = config.getint('Section1', 'int') - print float + int + print(float + int) # Notice that the next output does not interpolate '%(bar)s' or '%(baz)s'. # This is because we are using a RawConfigParser(). if config.getboolean('Section1', 'bool'): - print config.get('Section1', 'foo') + print(config.get('Section1', 'foo')) To get interpolation, you will need to use a :class:`ConfigParser` or :class:`SafeConfigParser`:: @@ -389,13 +389,13 @@ To get interpolation, you will need to use a :class:`ConfigParser` or config.read('example.cfg') # Set the third, optional argument of get to 1 if you wish to use raw mode. - print config.get('Section1', 'foo', 0) # -> "Python is fun!" - print config.get('Section1', 'foo', 1) # -> "%(bar)s is %(baz)s!" + print(config.get('Section1', 'foo', 0)) # -> "Python is fun!" + print(config.get('Section1', 'foo', 1)) # -> "%(bar)s is %(baz)s!" # The optional fourth argument is a dict with members that will take # precedence in interpolation. - print config.get('Section1', 'foo', 0, {'bar': 'Documentation', - 'baz': 'evil'}) + print(config.get('Section1', 'foo', 0, {'bar': 'Documentation', + 'baz': 'evil'})) Defaults are available in all three types of ConfigParsers. They are used in interpolation if an option used is not defined elsewhere. :: @@ -406,10 +406,10 @@ interpolation if an option used is not defined elsewhere. :: config = ConfigParser.SafeConfigParser({'bar': 'Life', 'baz': 'hard'}) config.read('example.cfg') - print config.get('Section1', 'foo') # -> "Python is fun!" + print(config.get('Section1', 'foo')) # -> "Python is fun!" config.remove_option('Section1', 'bar') config.remove_option('Section1', 'baz') - print config.get('Section1', 'foo') # -> "Life is hard!" + print(config.get('Section1', 'foo')) # -> "Life is hard!" The function ``opt_move`` below can be used to move options between sections:: |