Printing contents in particular section of configuration file in Python
Question: Lets imagine i have an config file by name sample.ini, let there be two
section in that.

    
    
        [section1]
        Name1 = Url_1
        Name2 = Url_2
    
        [Section2]
        Name3 = Url_3
        Name4 = Url_4
    

Now if I want to print Url_3 & Url_4, is there a way in Python that I can only
print those two Url.

I tried looking about this, but they provide solution which print every
section contents in config file.

Please help me with that.


Answer: Could you try giving this a shot? Using python's config parser

sample.ini

    
    
    [section1]
    Name1=Url_1
    Name2=Url_2
    
    [Section2]
    Name3=Url_3
    Name4=Url_4
    

Script:

    
    
    import ConfigParser as configparser
    
    parser = configparser.ConfigParser()
    parser.read("sample.ini")
    
    section_2 = dict(parser.items("Section2")) 
    print section_2["name3"]
    print section_2["name4"]
    

Output:

    
    
    Url_3
    Url_4
    

