Python Package configparser: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Python Language =Overview=")
 
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
* [[Python_Language#configparser|Python Language]]
* [[Python_Language#configparser|Python Language]]
=Overview=
=Overview=
=Handing AWS CLI Configuration Programmatically=
<syntaxhighlight lang='py'>
from configparser import ConfigParser
config_file = Path(Path.home(), ".aws/config")
parser = ConfigParser()
parser.read(config_file)
for section_name in parser.sections():
    print(f"section: {section_name}")
    section = parser[section_name]
    for k in section.keys():
        print(k)
    if 'role_arn' in section:
        print(f"{section_name} role_arn: {section['role_arn']}")
</syntaxhighlight>

Latest revision as of 18:09, 20 April 2023

Internal

Overview

Handing AWS CLI Configuration Programmatically

from configparser import ConfigParser

config_file = Path(Path.home(), ".aws/config")
parser = ConfigParser()
parser.read(config_file)

for section_name in parser.sections():
    print(f"section: {section_name}")
    section = parser[section_name]
    for k in section.keys():
        print(k)
    if 'role_arn' in section:
        print(f"{section_name} role_arn: {section['role_arn']}")