mirror of https://github.com/python/cpython
Merge #16085: Don't promote shadowing builtins in the configparser example.
This commit is contained in:
commit
a09fc13c07
|
@ -770,9 +770,9 @@ An example of writing to a configuration file::
|
||||||
# values using the mapping protocol or ConfigParser's set() does not allow
|
# values using the mapping protocol or ConfigParser's set() does not allow
|
||||||
# such assignments to take place.
|
# such assignments to take place.
|
||||||
config.add_section('Section1')
|
config.add_section('Section1')
|
||||||
config.set('Section1', 'int', '15')
|
config.set('Section1', 'an_int', '15')
|
||||||
config.set('Section1', 'bool', 'true')
|
config.set('Section1', 'a_bool', 'true')
|
||||||
config.set('Section1', 'float', '3.1415')
|
config.set('Section1', 'a_float', '3.1415')
|
||||||
config.set('Section1', 'baz', 'fun')
|
config.set('Section1', 'baz', 'fun')
|
||||||
config.set('Section1', 'bar', 'Python')
|
config.set('Section1', 'bar', 'Python')
|
||||||
config.set('Section1', 'foo', '%(bar)s is %(baz)s!')
|
config.set('Section1', 'foo', '%(bar)s is %(baz)s!')
|
||||||
|
@ -790,13 +790,13 @@ An example of reading the configuration file again::
|
||||||
|
|
||||||
# getfloat() raises an exception if the value is not a float
|
# getfloat() raises an exception if the value is not a float
|
||||||
# getint() and getboolean() also do this for their respective types
|
# getint() and getboolean() also do this for their respective types
|
||||||
float = config.getfloat('Section1', 'float')
|
a_float = config.getfloat('Section1', 'a_float')
|
||||||
int = config.getint('Section1', 'int')
|
an_int = config.getint('Section1', 'an_int')
|
||||||
print(float + int)
|
print(a_float + an_int)
|
||||||
|
|
||||||
# Notice that the next output does not interpolate '%(bar)s' or '%(baz)s'.
|
# Notice that the next output does not interpolate '%(bar)s' or '%(baz)s'.
|
||||||
# This is because we are using a RawConfigParser().
|
# This is because we are using a RawConfigParser().
|
||||||
if config.getboolean('Section1', 'bool'):
|
if config.getboolean('Section1', 'a_bool'):
|
||||||
print(config.get('Section1', 'foo'))
|
print(config.get('Section1', 'foo'))
|
||||||
|
|
||||||
To get interpolation, use :class:`ConfigParser`::
|
To get interpolation, use :class:`ConfigParser`::
|
||||||
|
|
Loading…
Reference in New Issue