# Is there a way to convert a Dataset tag to a list of values on the Script Console?

**URL:** <https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-dataset-tag-to-a-list-of-values-on-the-script-console/19758>\
**Category:** General Discussion\
**Created:** [September 20, 2018, 10:44pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-dataset-tag-to-a-list-of-values-on-the-script-console/19758 "2018-09-20T22:44:51Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lalillo1](https://avatars.discourse-cdn.com/v4/letter/l/a6a055/32.png) [@Lalillo1](https://forum.inductiveautomation.com/u/Lalillo1)\
**Post date:** [September 20, 2018, 10:44pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-dataset-tag-to-a-list-of-values-on-the-script-console/19758/1 "2018-09-20T22:44:51Z")

</div>

I have a Memory tag named “Criticals”. It is a Dataset type. It only has 1 column and 4 rows of numbers.  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/68596d7c4513465abaa00e914cc50c59ec2f30af.png)  
I am trying to use the Script Console to generate a list variable of 4 numbers. My goal is to later use that list of numbers in a scripting.  
I have tried various ways. Lastly, I tried something like this, but no success so far:

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/d/d7679a661206117fb1fd067caa2b962dd66f4eb1.png)

---

<div class="post-metadata">

**Author:** ![weertske](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/weertske/32/3353_2.png) [@weertske](https://forum.inductiveautomation.com/u/weertske)\
**Post date:** [September 20, 2018, 11:14pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-dataset-tag-to-a-list-of-values-on-the-script-console/19758/2 "2018-09-20T23:14:42Z")

</div>

I haven’t looked at the rest of your code, but your first mistake is with:  
Dataset = system.tag.read(“MX\_Seating/R1Cx\_01B/Criticals”).data

data is not an attribute of a tag read, use value:  
Dataset = system.tag.read(“MX\_Seating/R1Cx\_01B/Criticals”).value

---

<div class="post-metadata">

**Author:** ![Lalillo1](https://avatars.discourse-cdn.com/v4/letter/l/a6a055/32.png) [@Lalillo1](https://forum.inductiveautomation.com/u/Lalillo1)\
**Post date:** [September 20, 2018, 11:19pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-dataset-tag-to-a-list-of-values-on-the-script-console/19758/3 "2018-09-20T23:19:12Z")

</div>

Thank you,

I just found out that I can read from a Dataset tag this way:

> print system.tag.read("MX\_Seating/R1Cx\_01B/Criticals").value.getValueAt(0, 0)  
> print system.tag.read("MX\_Seating/R1Cx\_01B/Criticals").value.getValueAt(1, 0)  
> print system.tag.read("MX\_Seating/R1Cx\_01B/Criticals").value.getValueAt(2, 0)  
> print system.tag.read("MX\_Seating/R1Cx\_01B/Criticals").value.getValueAt(3, 0)

However, now I am trying to figure out how can I loop only for the row values and not the column since column will stay as Column 0. Any suggestions?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 20, 2018, 11:24pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-dataset-tag-to-a-list-of-values-on-the-script-console/19758/4 "2018-09-20T23:24:24Z")

</div>

```auto
tagValue = system.tag.read("MX_Seating/R1Cx_01B/Criticals").value
listOfRowValues = []
for row in range(tagValue.rowCount):
    listOfRowValues.append(tagValue.getValueAt(row, 0)

```

---

<div class="post-metadata">

**Author:** ![Lalillo1](https://avatars.discourse-cdn.com/v4/letter/l/a6a055/32.png) [@Lalillo1](https://forum.inductiveautomation.com/u/Lalillo1)\
**Post date:** [September 20, 2018, 11:37pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-dataset-tag-to-a-list-of-values-on-the-script-console/19758/6 "2018-09-20T23:37:24Z")

</div>

Thank you very much:

```auto
tagValue = system.tag.read("MX_Seating/R1Cx_01B/Criticals").value
listOfRowValues = []
for row in range(tagValue.rowCount):
    listOfRowValues.append(tagValue.getValueAt(row, 0))
    print tagValue.getValueAt(row,0)

```

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [September 21, 2018, 7:02pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-dataset-tag-to-a-list-of-values-on-the-script-console/19758/7 "2018-09-21T19:02:50Z")

</div>

You can also move it over to a pyDataSet and run through it that way.  
I prefer to since then I don’t have to use the getValueAt

```auto
 listOfRowValues=[]	
      t = system.dataset.toPyDataSet(system.tag.read("MX_Seating/R1Cx_01B/Criticals").value)
 	     for row in t:
 	          listOfRowValues.append(row[0])
                  print row[0]

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [September 21, 2018, 8:30pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-dataset-tag-to-a-list-of-values-on-the-script-console/19758/8 "2018-09-21T20:30:39Z")

</div>

+1 to what @MMaynard said. As an aside, the “pythonic way” (FWIW) would be to use a list comprehension:

```python
t = system.dataset.toPyDataSet(system.tag.read("MX_Seating/R1Cx_01B/Criticals").value)
listOfRowValues = [row[0] for row in t]
print listOfRowValues

```

* * *

It’s also worth noting that the time may come when you have a two dimensional dataset to work with. In that instance, you might want to use a list of lists. The approach is very similar:

```python
t = system.dataset.toPyDataSet(system.tag.read("MX_Seating/R1Cx_01B/Criticals").value)
# note the use of list() to create the entry
listOfRowValues = [list(row) for row in t]
print listOfRowValues

```

---

<div class="post-metadata">

**Author:** ![Lalillo1](https://avatars.discourse-cdn.com/v4/letter/l/a6a055/32.png) [@Lalillo1](https://forum.inductiveautomation.com/u/Lalillo1)\
**Post date:** [September 21, 2018, 10:39pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-dataset-tag-to-a-list-of-values-on-the-script-console/19758/9 "2018-09-21T22:39:01Z")

</div>

Thank you very much!

---

<div class="post-metadata">

**Author:** ![Lalillo1](https://avatars.discourse-cdn.com/v4/letter/l/a6a055/32.png) [@Lalillo1](https://forum.inductiveautomation.com/u/Lalillo1)\
**Post date:** [September 21, 2018, 10:39pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-dataset-tag-to-a-list-of-values-on-the-script-console/19758/10 "2018-09-21T22:39:33Z")

</div>

I appreciate your help. Many many Thanks!!

---

<div class="post-metadata">

**Author:** ![hachjessed](https://avatars.discourse-cdn.com/v4/letter/h/7ab992/32.png) [@hachjessed](https://forum.inductiveautomation.com/u/hachjessed)\
**Post date:** [March 11, 2020, 9:15pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-dataset-tag-to-a-list-of-values-on-the-script-console/19758/11 "2020-03-11T21:15:21Z")

</div>

How would you return a straight list from a PyDataSet?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 11, 2020, 9:29pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-dataset-tag-to-a-list-of-values-on-the-script-console/19758/12 "2020-03-11T21:29:10Z")

</div>

The most ‘pythonic’ way to get a doubly-nested list would probably be:  
`ll = [[l] for l in l]`

Or less efficient but maybe less ‘magic’ (depending on who you’re talking to):  
`ll = list(map(lambda x: [x], l))`

Either way, you could then run `system.dataset.toPyDataset`:  
`pds = system.dataset.toPyDataset(["values"], ll)`

Note that datasets, and therefore PyDatasets, require ‘columns’ to have the same type, so `[[o] for o in ['abc', 123]]` will not be able to convert into a PyDataset.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 11, 2020, 10:28pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-dataset-tag-to-a-list-of-values-on-the-script-console/19758/13 "2020-03-11T22:28:18Z")

</div>

Are you looking for a list of lists _[[a,b,c], [d,e,f]]_ or a flat list _[a,b,c,d,e,f]_ ?

---

<div class="post-metadata">

**Author:** ![hachjessed](https://avatars.discourse-cdn.com/v4/letter/h/7ab992/32.png) [@hachjessed](https://forum.inductiveautomation.com/u/hachjessed)\
**Post date:** [March 12, 2020, 12:10am UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-dataset-tag-to-a-list-of-values-on-the-script-console/19758/14 "2020-03-12T00:10:19Z")

</div>

I would be looking for a flat list.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 12, 2020, 1:29am UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-dataset-tag-to-a-list-of-values-on-the-script-console/19758/15 "2020-03-12T01:29:36Z")

</div>

WARNING: I typed this on my phone. 😉  
EDIT: Verified my snippet upon getting to my desk.

```python
# Create PyDataSet
headers = ['col1', 'col2', 'col3']
data = [[1,2,3], [4,5,6], [7,8,9]]
ds = system.dataset.toPyDataSet(system.dataset.toDataSet(headers, data))

flatList =[]

for row in ds:
	flatList.extend(list(row))
	
print flatList

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 12, 2020, 3:23pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-dataset-tag-to-a-list-of-values-on-the-script-console/19758/16 "2020-03-12T15:23:58Z")

</div>

Or if we’re [golfing](https://en.wikipedia.org/wiki/Code_golf), `flatlist = [item for sublist in data for item in sublist]` 🙂

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 12, 2020, 6:25pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-convert-a-dataset-tag-to-a-list-of-values-on-the-script-console/19758/17 "2020-03-12T18:25:00Z")

</div>

> [@paul-griffith](#):
>
> Or if we’re [golfing](https://en.wikipedia.org/wiki/Code_golf)

Huh. Millenial whippersnappers with cute new slang. No golf on my lawn!
