Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: linnoinenHi everyone,
I'm tackling with a specific problem regarding an file output.
I've connected two nodes to a file, which are collected together to form a file (using the CAT node).
On node creates a custom header row, the other is the body of the file.
3,3,X,,
Transaction1,1,X,,
Transaction2,1,X,,
Transaction3,1,X,,
This file contains a header row, which has previously calculated the number of rows below (3), the sum of the second column (3) and then a flag for an indicator (X).
Transaction rows below the header contain the transaction number (Transaction#), a value (1), an indicator flag (X) and a blank column.
The system this file is being read into requires that the first row does not have this blank column.
I have two options on how to output this file:
1) As the file is in CSV format, I can manipulate the indicator flag column to include the commas and drop the blank column: "X,,"
The problem with this is that as my delimiter is a comma, this column will be escaped by quotation marks, which I would need to remove.
2) Create the file as in the above example and then run a node to postprocess the file, and remove the two commas from the first line of the file.
I have a snippet of Python code which should do the job for option 1, but I'm unsure of which Python node to use. Also, where should the code be inserted in the node?
with open('c:\tmp\test.csv', 'r') as infile,
open('c:\tmp\test_mod.csv','w') as outfile:
data = infile.read()
data = data.replace("\"","")
outfile.write(data)
Any suggestions are more than welcome!
/Karri