Is there a way for the reader to ignore these linebreaks?
Is there a way for the reader to ignore these linebreaks?
Best answer by david_r
Hi,
I does not seem like FME supports CSV files with newlines, even when they are quoted.
Try to insert the following script into a PythonCreator, it uses the Python CSV module which supports newlines:
import fmeobjects
import csv
class FeatureCreator(object):
def __init__(self):
self.inputfilename = FME_MacroValues['INPUT_CSV_FILE']
self.csvdelimiter = ',' # Modify as needed
self.csvquotechar = '"' # Modify as needed
self.log = fmeobjects.FMELogFile()
self.fieldnames = []
def close(self):
with open(self.inputfilename, 'rb') as csvfile:
csvreader = csv.reader(csvfile,
delimiter=self.csvdelimiter,
quotechar=self.csvquotechar)
for n, row in enumerate(csvreader):
if n == 0:
self.fieldnames = row
self.log.logMessageString("Attribute names to expose " + \
"in the PythonCreator:", fmeobjects.FME_WARN)
for field in row:
self.log.logMessageString(" "+field, fmeobjects.FME_WARN)
else:
feature = fmeobjects.FMEFeature()
for m, value in enumerate(row):
feature.setAttribute(self.fieldnames[m], value)
self.pyoutput(feature)
Notes:
Hope this helps.
David
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.