Manipulating DataSets and PyDataSets

Hi all,
My goal is to execute a select query, and then for each row assign “ASDF” to column 2. Sounds simple enough, but I’m still having trouble :neutral_face:.
This is the code I have:

penList = fpmi.db.runQuery(query) penListDataSet = fpmi.dataset.toDataSet(penList) for i in range(len(penList)): fpmi.dataset.updateRow(penListDataSet, i, {2: "ASDF"})
The problem is that when I check the penListDataSet values of column 2 afterwards, they are still the old values! I have also tried using the column name instead of the index, and I have tried using setValue instead of updateRow. In all cases I still get the same result. I have also tried editing penList directly, which is a PyDataSet, but this gives an error. Is my mistake just too obvious for me to see?
Also, what are the differences between PyDataSets and DataSets? I’ve noticed that I get errors when I use len() on a DataSet, or if I use a DataSet in a for loop (ie: “pen in penListDataSet”). Alternatively, I get errors whenever I try to do any editing of a row in a PyDataSet. Is this all to be expected?

Thanks in advance,
Charles

Ok, let me clear some things up here.

FactoryPMI components use DataSets. PyDataSets are wrappers around a DataSet that allow them to behave nicely in Python, thus they support len() and simple iteration, etc. You can convert between the two quite readily.

Both PyDataSets and DataSets are immutable, which is the root of your problems. This is why updating the PyDataSet is giving you an error, and why you’re not seeing your edits go through.

The fpmi.dataset.updateRow function does not actually modify the input dataset, because, as I mentioned above, datasets are immutable. It returns a new dataset. Try this:

penList = fpmi.db.runQuery(query) penListDataSet = fpmi.dataset.toDataSet(penList) for i in range(len(penList)): penListDataSet = fpmi.dataset.updateRow(penListDataSet, i, {2: "ASDF"})

1 Like

:bulb: Ahhhhhhhh. Of course.
Thanks a lot for you help.

No problem - glad to clear this up, it is an admittedly confusing topic.