Python利用ConfigParser

发布时间:2019-08-28 09:10:14编辑:auto阅读(1489)

    #!/usr/bin/python
    # -*- coding:utf-8 -*-

    import ConfigParser

    config = ConfigParser.ConfigParser()
    config.read("flashfxp.ini")
    sections = config.sections()
    print sections
    options = config.options("CmdWindow")
    print options
    items = config.items("CmdWindow")
    print items

    context1 = config.get("main","optdata")
    print context1
    context2 = config.get("LiveUpdate","Interval")
    print context2

    -----------------------------------------flashfxp.ini----------------------------

    [main]
    optdata=eJwzMTAxMODlMgFSpmDKCEqZQSgLMGViyMsFAI+xBn4=
    build=1240
    setup=40400
    FileExists=000000000
    QHistoryMax=50
    Options=1001000010000010011010011111111000000101111101110000000010000000000100110010011041100000000210010111111113001111010100

    [LiveUpdate]
    Interval=15

    [QuickConnect]
    Left=0
    Top=0
    Width=424
    Height=260
    State=0

    [Graph]
    V=0
    H=65

    [window]
    Left=124
    Top=69
    Width=1093
    Height=614
    State=0
    TS=0.5
    BS=0.5
    CS=0.75
    LTS=0
    RTS=0
    THP=546

    [CmdWindow]
    Y=0.629999995231628
    W=454
    H=377

    [statuswin]
    Left=383
    Top=154
    Width=592
    Height=411
    State=0
    Font="宋体", 8, [], [clWindowText], 134
    Color=-2147483643
    OnTop=0
    Wrap=0

    -----------------------------------------the result-------------------------

    ['LiveUpdate', 'CmdWindow', 'Graph', 'window', 'QuickConnect', 'main', 'statuswin']
    ['y', 'w', 'h']
    [('y', '0.629999995231628'), ('w', '454'), ('h', '377')]
    eJwzMTAxMODlMgFSpmDKCEqZQSgLMGViyMsFAI+xBn4=
    15

关键字