LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Python -- Output the results

    Employee
    Posted 09-01-2015 10:54

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Bryt Park

    Hi,

    The following code can output my results but it keeps overwriting previous output, so I am always only getting the last line.
    How can I make it output all the results, append rather than overwrite? thanks!

    def Process(self, filename):				
    	success = False			
    	outRec = self.outputs[0].newRecord()		
    	with open(filename,'rU') as f:			
    		reader = csv.reader(f))	
    		for row in reader:	
    			outRec["ImportedData"] = row
    	self.outputs[0].write(outRec)		
    	success = True


  • 2.  RE: Python -- Output the results

    Employee
    Posted 09-01-2015 11:17

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: stonysmith

    You simply need to move the write(outrec) to within the for() loop...
    def Process(self, filename):				
    	success = False			
    	outRec = self.outputs[0].newRecord()		
    	with open(filename,'rU') as f:			
    		reader = csv.reader(f))	
    		for row in reader:	
    			outRec["ImportedData"] = row
    	                self.outputs[0].write(outRec)		
    	success = True


  • 3.  RE: Python -- Output the results

    Employee
    Posted 09-01-2015 12:44

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Bryt Park

    Ahhh...... thanks!