Back to SDS/2 Parametric Scripts

 

### READ FILE DATA

 

''' File Data

''' File Data

$

$ SET 10

$

$ hjdsahclaladsalkjls

$PTITLE = SET 10 = SET_110

SET 10 = 1101 1106 1107 1108 1109 1110 1111,

1112 1113 1114 1115 1116 1117 1118,

1119 1120 1121 1122 1123 1124 1125

$ END OF SET 110

$

$

 

SET 11 = 11031 11036 11037 11038 11040 11050 11051,

11052 11053 11054 11055 11056 11057 11058,

$ END OF SET 11

$

$

SET 15 = 110131 110136 110137 110138 110410 110510 110511,

110512 110513 110514 110515 110516 110517 110518,

$ END OF SET 15

$

$

 

SET 19 = 23758 18859 26430 69473 85960 865843 9586 634 3664,

4858 895786 9488 0509 98895,

5488,

4395 9590,

$ END OF SET 19

$

SET 1 = 1 THRU 897

$HMSET

SET 2 = 1 THRU 932

$HMSET

'''

 

def file_data(s):

    outStr = ''

    in_set = False

    for line in s:

        if line.startswith('SET'):

            if 'THRU' in line:

                in_set = False

                outStr += line.replace('THRU ', '').strip('\n').strip(',')+'\n'

            else:

                in_set = True

                outStr += line.strip('\n').strip(',')

        elif 'END OF SET' in line:

            in_set = False

            outStr += '\n'

        elif in_set:

            outStr += ' ' + line.strip('\n').strip(',')

    dataDict = {}

    for line in outStr.strip().split('\n'):

        dataDict[line.split('=')[0].strip()] = [int(x) for x in line.split('=')[1].strip().split()]

    return dataDict

 

dd = file_data(open('H:/TEMP/temsys/strdata.txt').readlines())

for key in dd:

    print '%s = %s' % (key, dd[key])

 

'''

# write data to file

f = open("your_file",'w')

for key in sorted(dd):

    f.write('%s %s\n' % (str(key), ''.join(repr(dd[key]).strip('[]').split(','))))

f.close()

'''

 

'''

# write data to file

f = open("H:/TEMP/temsys/strdataOut.txt",'w')       

for key in sorted(dd):

    f.write('%s = %s\n' % (key, dd[key]))

f.close()

'''

 

'''>>> SET 10 = 1101 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125

SET 11 = 11031 11036 11037 11038 11040 11050 11051 11052 11053 11054 11055 11056 11057 11058

SET 15 = 110131 110136 110137 110138 110410 110510 110511 110512 110513 110514 110515 110516 110517 110518

 

SET 15 = [110131, 110136, 110137, 110138, 110410, 110510, 110511, 110512, 110513, 110514, 110515, 110516, 110517, 110518]

SET 19 = [23758, 18859, 26430, 69473, 85960, 865843, 9586, 634, 3664, 4858, 895786, 9488, 509, 98895, 5488, 4395, 9590]

SET 11 = [11031, 11036, 11037, 11038, 11040, 11050, 11051, 11052, 11053, 11054, 11055, 11056, 11057, 11058]

SET 10 = [1101, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1120, 1121, 1122, 1123, 1124, 1125]

>>>

>>> sum(dataDict['SET 10'])

23411

>>>

'''