jmunsch

write to cell example

Jun 30th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1.     def writeToCell(self,sku, header_name, cell_input):
  2.         '''
  3.        Creates a copy of a file and writes to a cell
  4.        '''
  5.         line_list = self.orig.replace('\r','').split('\n')
  6.         self.infoLogger(type(cell_input),type(row_index),type(column_index))
  7.         results = returnRowBySku(sku) #[[headers],[line]]
  8.         self.header_index = results[0].index(header_name)
  9.         results[1][self.header_index] = cell_input
  10.         self.tmp = self.orig.replace('\r','')
  11.         lines = self.tmp.split('\n')
  12.         insert_line = ','.join(results[1][self.header_index])
  13.        
  14.         final_list = []
  15.         for line in lines:
  16.             if insert_line in line:
  17.                 final_list.append(insert_line)
  18.             else:
  19.                 final_list.append(line)
  20.         if len(final_list) is 0:
  21.             print(traceback.format_exc())
  22.             exit()
  23.         results = self.writeCsvFile('\n'.join(final_list))
  24.         return results
Advertisement
Add Comment
Please, Sign In to add comment