I was pointed to a .proj file yesterday concerning csv manipulation, and the program is exactly what I’m looking for. I understand what the program is doing with the buttons, but if I were to want to use this idea again for a project of my own, I’m not sure I completely understand the scripting on one of the buttons. I was wondering if someone could help me out and maybe hit on some major points of this script or even point me to a walkthrough on how this process is started from the ground up. I’ve already been referring to the ignition handbook and the ‘official python help guide’ but I’m looking for something more straightforward.
I’m looking for a little help on the first three lines (where is it importing these things from?)
Right before the main for loop starts dataOut is defined as [], what does that mean? It’s an open ended dataset?
In the main body of the Code I understand that it is translating the text area into a csv format, but what does rowOut and dataOut do at the end of the body?
This is the Code:
[code]import StringIO
import csv
from java.text import SimpleDateFormat as SDF
dataIn=StringIO.StringIO(event.source.parent.getComponent(‘Text Area’).text)
reader=csv.reader(dataIn, delimiter=’,’, quotechar="’")
dataOut=[]
headerFlag=1
typeFlag=0
for row in reader:
element=[r.strip() for r in row]
if headerFlag==1:
headers=element
headerFlag=0
typeFlag=1
elif typeFlag==1:
types=element
typeFlag=0
print types
else:
rowList=list(element)
rowOut=[]
for i in range(len(element)):
type=types[i].strip()
if type==“Integer”:
dataPoint=(int(rowList[i]))
elif type==“Float”:
print rowList[i]
dataPoint=(float(rowList[i]))
elif type==“String”:
if str(rowList[i])[:2]==“u’”:
dataPoint=unicode(str(rowList[i])[2:-1])
else:
dataPoint=(str(rowList[i]))
elif type==“Boolean”:
dataPoint=((rowList[i]==‘True’))
elif type==“Date”:
inputFormat=SDF(“EEE MMM dd HH:mm:ss Z yyyy”)
dataPoint=SDF.parse(inputFormat,str(rowList[i]))
rowOut.append(dataPoint)
dataOut.append(rowOut)
event.source.parent.getComponent(‘Table’).data=system.dataset.toDataSet(headers,dataOut)[/code]
This may not be the best place to get this sort of help, but I figured this would be the best place to start! Thanks in Advance for the help!