# Test ConfigureParser

 

from ConfigParser import ConfigParser

 

fn = r'H:\TEMP\temsys\HAMMER.INI'

 

class Ini:

    def getinifile (self, f, sect, item, default):

        fp = open(f)

        p = ConfigParser()

        p.readfp(f)

        print dir(p)

        print p.items('X Axis')

        print p.sections()

        v = p.get(sect, item)

        print v

        if len(v) == 0:

            v = default

        return v

 

value = Ini().getinifile(fn, 'X Axis', 'CallOutMax.1', 'default' )

print value

 

'''

>>> ConfigParser().__doc__

>>> fp = open(r'H:\TEMP\temsys\HAMMER.INI')

>>> p = ConfigParser()

>>> p.readfp(fp)

>>> p.set('X Axis', 'usage', '0x90')

>>> p.write(fp)

Traceback (most recent call last):

  File "<interactive input>", line 1, in ?

  File "C:\Python23\lib\ConfigParser.py", line 363, in write

    fp.write("[%s]\n" % section)

IOError: (0, 'Error')

>>> p.items('X Axis')

[('name', 'X AXIS'), ('linedata.1', '(310,60),(310,76),(268,76)'), ('usage', '0x90'), ('calloutmax.1', '(296,17),(386,59)'), ('type', '0x2'), ('usagepage', '0x1'), ('align.1', 'BL')]

>>> p.write(open(r'H:\TEMP\temsys\HAMMER1.INI', 'w'))

>>>

'''