does Ignition not support comprehension? this isn't working, but it's valid code:
#
# 'value' is the entire dataset, we only want the assetName at this point
#
assetNames = {}
py_value = system.dataset.toPyDataSet(value)
for item in py_value: # β column β data
assetNames = {**assetNames,**{'assetName':item['assetName']}}
return [assetNames] #<--- cuz everything needs to be a list... :)
i am building a table but only require one column from the dataset to populate the table. this should return a dict of key:value pairs (column and data)... but it isn't.
AFAIK, the table parses a data object of key:value pairs; the key is the column name, the value is, well, the value. this should deliver what the table parser is looking for.
okay. read the whole post (very good). but i hit a hiccup: i originally had tried this:
assetNames = {}
py_value = system.dataset.toPyDataSet(value)
for item in py_value:
assetNames.update({'assetName':item['assetName']})
return [assetNames] #<--- cuz everything needs to be a list... :P
which, ironically, is EXACTLY what the SO post explained (so i'm not actually an idiot after all...). but it only returned a single element (the LAST element): [{assetName: 70456-20}] so i went the comprehension route. so i'm not sure what's going on here.
i was, as i mentioned, trying to build a table but only using ONE of the columns of data. so i don't know if your method would work, but i'll give it a shot with an explicitheader definition and see what happens. i am not familiar with the dict method or what it does... so some reading first??? nah. slam it in there!! learn from the pieces!!
You can use them in python 2 as well. No issue here.
try the line I posted above.
And if you want to update a dict in just one expression without having to use update, which is a pain to use in comprehension anyway because it doesn't return the updated dict:
new_dict = dict(new_key=some_value, **old_dict)
this can be used in comprehension easily
[dict(k=v, **old_dict) for k, v other_dict.items()]
{k:v for k, v in dict.items()}
absolutely works in python 2. What do you call comprehension ?
You may not be able to do them with the **someDict but you can certainly make dicts on the fly with comprehensions as @PGriffith did in this post , kind of related as well with going from a ds to a dict
Though maybe this counts as a list comprehension, but if the final result is a dict, its a dict comprehension in my book lol.
data visualization tools in Ignition scripting still suck (Python β prettyPrint, c'mon)
i need more prayers to God that my higher-ups let me implement a better IDE strategy soon
β i don't need to convert everything to py_dataset β
i may actually commit seppuku before i get my head around this environment
thank you for all your help and comments. very helpful at keeping the blade at bay.
EDIT: i've always had difficutly visualizing anything, period. once it does click, though, it stays forever. so please bear with as i keep trying to 'see' how this stuff hangs together. very irritating disability for a coder... meditation? forget it.
In my experince PyDataSets are most useful when you want access to all or almost all columns in a dictionary. So for things like
for (someCol1, someCol2, someCol3) in system.dataset.toPyDataSet(ds):
# do something with your extracted columns
# don't need to fetch them via col1=row['someCol1']
# or via col1 = ds.getValueAt(row,'someCol1') if a basic dataset