"""
few functions to massage into lisp data
python functions to convert arff files to lisp
only works on csv file with no other junk
chet tobrey
feb 27 2008
Modified very slightly and poorly by Peter Santiago on June 10,2008 to convert arff to a lisp array.
"""
def addParens (s):
   lispStr = '(' + s + ')\n'
   lispStr = lispStr.replace('e+','')
   lisrStr = lispStr.replace('e-','')
   return lispStr

def lispify(f):
    lispData = []
    counterrows = 0
    temp = ''
    for line in f:
	if line[0]!='@':
       		line = line.rstrip('\r\n')
        	line = kill_columns(line,0)#must set to zero or otherwise this returns a list
      	  	temp = ''
        	counterrows +=1
      		for elt in line:
          		 temp1 = str(elt)
          		 temp += (temp1 +' ')
       
       		lispData += addParens(temp)
       		print 'rows' , counterrows
    return lispData

def kill_columns(data,how_many):
   """takes a string of cs values and removes specified
   number of columns from front"""
   temp = data.split(',')

   for i in range(how_many):
      temp.pop(0)
   return temp

def Main():
    """change filename here to use on other files"""
    inFile =raw_input('Enter the file name\n')
    #print ("This is a test line to make sure something is happening.")
    f = open(inFile)
    data = f.readlines()
    f.close()

    num_cols=(len(data[0].split(','))) #-105 for all_data mystery
    lispData = lispify(data)
    g = open((inFile.split('.')[0])+'.matrix','w')
    data_list =[]
    
    for line in lispData:
       data_list +=line
   
    att_list = data_list
 
    #att_list = data_list
    att_list.append(('\n)'))
    g.write("#2A(\n")
    for elt in att_list:
       	g.write(elt)
    g.close()


Main()
    
    
