Iterate over row columns

Adding to this old thread in case anyone else wanting to iterate over RowObject ended up here as I did. This was the only thread Google provide and the answers weren’t quite what I needed, but they were enough to point me in the right direction.

I wanted to use a row object in a dictionary comprehension. So something like:

my_copy = {k:v for k,v in self.item.items()}

where self.item was a <LiveObject: anvil.tables.Row>

Alas it cannot be done like that as an anvil.tables.Row doesn’t have a items method. Nor can you cheat with:

my_copy = {k:self.item[k] for k in self.item}

In this case the items returned are a tuple where element at index 0 is the column name, index 1 is the value.

So do actually achieve what I wanted the required code was:

my_copy = {k[0]:k[1] for k in self.item}