Snippet:Read AIMMS .lis file

From HUES Platform Wiki
Description Python script for reading AIMMS .lis file which describes which AIMMS variable corresponds to the cplex input variable name
Author(s) Boran Morvaj
Language Python
Tags AIMMS, Python, cplex
Snippet code ####################
def readlisting(filename):
   try:
       filetxt=open(filename)
       line=filetxt.readline()
       idx=1
       while True:#going through header until 'Column' word is found
               line=filetxt.readline()
               idx+=1
               if len(line.split())>0:
                   if line.split()[0]=='Column':
                       break
           
       filetxt.readline()#skipping empty line after 'Column'
           
       data=[]#list
       while True:#writing variables into data
               line=filetxt.readline()
               
               if len(line.split())==0:
               
                   break
               data.append(line.split()[1])#add only 2nd column
           
       
       filetxt.close()
       return data
   except:
       return 'Error, couldn\'t open the file'
Notes