config = configparser.ConfigParser()
config.sections()

config.read('example.ini')

config.sections()

'bitbucket.org' in config

'bytebong.com' in config

config['bitbucket.org']['User']

config['DEFAULT']['Compression']

topsecret = config['topsecret.server.com']

topsecret['ForwardX11']

topsecret['Port']

for key in config['bitbucket.org']:
    print(key)

config['bitbucket.org']['ForwardX11']

type(topsecret['Port'])

type(int(topsecret['Port']))

type(topsecret.getint('Port'))

type(topsecret.getfloat('Port'))

int(topsecret['Port']) - 22.0

int(topsecret['Port']) - 22

try:
    topsecret.getint('ForwardX11')
except ValueError:
    print(True)

topsecret.getboolean('ForwardX11')

config['bitbucket.org'].getboolean('ForwardX11')

config.getboolean('bitbucket.org', 'Compression')

topsecret.get('Port')

topsecret.get('CompressionLevel')

topsecret.get('Cipher')

topsecret.get('Cipher', '3des-cbc')

"""
Explanation: Now that we have created and saved a configuration file, let’s read it back and explore the data it holds.
End of explanation
"""


topsecret.get('CompressionLevel', '3')

"""
Explanation: Please note that default values have precedence over fallback values. For instance, in our example the 'CompressionLevel' key was specified only in the 'DEFAULT' section. If we try to get it from the section 'topsecret.server.com', we will always get the default, even if we specify a fallback:
End of explanation
"""


'BatchMode' in topsecret

topsecret.getboolean('BatchMode', fallback=True)

config['DEFAULT']['BatchMode'] = 'no'
topsecret.getboolean('BatchMode', fallback=True)

import yaml

with open("config.yml", 'r') as ymlfile:
    cfg = yaml.load(ymlfile)

for section in cfg:
    print(section)
print(cfg['mysql'])
print(cfg['other'])

# Load the configuration file
with open("config.yml") as f:
    sample_config = f.read()
config = configparser.RawConfigParser(allow_no_value=True)
config.readfp(io.BytesIO(sample_config))

# List all contents
print("List all contents")
for section in config.sections():
    print("Section: %s" % section)
    for options in config.options(section):
        print("x %s:::%s:::%s" % (options,
                                  config.get(section, options),
                                  str(type(options))))

# Print some contents
print("\nPrint some contents")
print(config.get('other', 'use_anonymous'))  # Just get the value
print(config.getboolean('other', 'use_anonymous'))  # You know the datatype?

"""
Explanation: The same fallback argument can be used with the getint(), getfloat() and getboolean() methods, for example:
End of explanation
"""


