Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: mzhaoI am building a library node that reads input files with or without a head. For the files without a head, I use a python node to read in data rows; and for the files with a head, I use the core::Delimited File node. After that, I use a core::Cat node to concatenate the two streams as the output (there is only one stream that has data).
This works fine for files that do have a head. However it has two errors for files without a head:
1. Because there is no input to the Delimited File node, its output is empty (no metadata). That causes a failure in the core::Cat node.
2. The Delimited File node is inside a composite, which defines FieldDelimiter and RecordDelimiter parameters. For files without a head, these two parameters are not needed and thus not defined. The Delimited File node triggers a “parameter <…> is not defined” error.
To avoid the two errors, I try to build a python node to implement the same function as the Delimited File node (If there is any workaround, I shouldn’t build this node).
In building the node, I have some difficulty in using and updating self.outputs[0].metadata.
I added code under initialize(self):, to ensure the output pin has metadata even the input to the node had no data, as below:
def initialize(self):
''' Called at node initialization, before first pump.'''
super(BrainNode, self).initialize()
om = self.newMetadata()
om.append("FileName", "string")
self.outputs[0].metadata = om
However, after that I could not change metadata, where in the pump(self, quant) function, I wanted to add output columns to the metadata using those read from the first row of the input data.
• I added self.outputs[0].metadata.append("Column1", "string") inside the pump function. I noticed len(self.outputs[0].metadata) became 2 after that, but Column1 did not appear in the output.
• When I ppended column1 to another variable, say om2, and then self.outputs[0].metadata = om2, I received an error metadata already defined.