I have a dataset row.
Need to get a value from it. Currently doing this:
start_time = row['STARTTIME']
However, for some reason, sometimes STARTTIME
could not exist in the dataset, so that line throws an exception.
Anyone knows if there is equivalent function like .get()
with a dictionary.
Looking for something simpler that cehcking if the column exists.
Thanks in advance.
You can use system.dataset.getColumnHeaders(dataset)
to get a list of columns in the dataset.
Try something like:
# initialize start_time
start_time = 'na'
# get start_time if it is available
if 'STARTTIME' in system.dataset.getColumnHeaders(dataset):
start_time = row['STARTTIME']
I'm doing something really similar, looking for something simpler or cleaner like .get
.
Thanks for the help anyway!
system.dataset | Ignition User Manual
The closest thing I know of to what I believe you are asking for are the getColumnIndex(<column-name>)
function or getValueAt(<row>, <column>)
.
In both cases if the column does not exist in the dataset a java.lang.ArrayIndexOutOfBoundsException
will be thrown so you will still need to use a try/except block to catch it. But it would definitely work to check if the column exists.
1 Like
There's no safe get operator on Dataset or PyDataset.
3 Likes