# Object has no attribute 'append'

**URL:** <https://forum.inductiveautomation.com/t/object-has-no-attribute-append/76605>\
**Category:** Ignition\
**Tags:** scripting, perspective\
**Created:** [July 19, 2023, 7:34pm UTC](https://forum.inductiveautomation.com/t/object-has-no-attribute-append/76605 "2023-07-19T19:34:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexZanduR](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alexzandur/32/31297_2.png) [@AlexZanduR](https://forum.inductiveautomation.com/u/AlexZanduR)\
**Post date:** [July 19, 2023, 7:34pm UTC](https://forum.inductiveautomation.com/t/object-has-no-attribute-append/76605/1 "2023-07-19T19:34:58Z")

</div>

tableDS.append([defect, count, level]) line giving me issues saying object has no attribute 'append'.  
Honestly stuck as this was working code and now it's not.

Thanks!

```auto
def defineLevel(count):
		if count >= 0 and count < 3:
			level = 0
		if count >= 3 and count < 5:
			level = 1
		if count >= 5 and count < 8:
			level = 2
		if count >= 8:
			level = 3
		return level
	
	end = system.date.now()
	start = system.date.addHours(end, -8)
	params = {"start":start, "end":end}
	ds = system.db.runNamedQuery("QualityDisplays", "Escalation/Table", params)
	tableDS = []
	headers = ["Defect", "Count", "Level"]
	
	for i in range (ds.getRowCount()):	
		defect = ds.getValueAt(i,0)
		count = ds.getValueAt(i,1)
		level = defineLevel(count)
		tableDS.append([defect, count, level])
		tableDS = system.dataset.toDataSet(headers, tableDS)	

	system.tag.write("[.]Active Dataset", tableDS)
```

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [July 19, 2023, 7:37pm UTC](https://forum.inductiveautomation.com/t/object-has-no-attribute-append/76605/2 "2023-07-19T19:37:27Z")

</div>

You are changing `tableDS` to a dataset each loop, unindent the last line of the loop

> [@AlexZanduR](#):
>
> ```auto
> for i in range (ds.getRowCount()):	
> defect = ds.getValueAt(i,0)
> count = ds.getValueAt(i,1)
> level = defineLevel(count)
> tableDS.append([defect, count, level])
> tableDS = system.dataset.toDataSet(headers, tableDS)
> 
> ```

should be

```auto
	for i in range (ds.getRowCount()):	
		defect = ds.getValueAt(i,0)
		count = ds.getValueAt(i,1)
		level = defineLevel(count)
		tableDS.append([defect, count, level])
	tableDS = system.dataset.toDataSet(headers, tableDS)

```

Edit: I agree with what Tim said below, don't reuse variables, just make another.

---

<div class="post-metadata">

**Author:** ![Tim\_Carlton](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim_carlton/32/52835_2.png) [@Tim\_Carlton](https://forum.inductiveautomation.com/u/Tim_Carlton)\
**Post date:** [July 19, 2023, 7:38pm UTC](https://forum.inductiveautomation.com/t/object-has-no-attribute-append/76605/3 "2023-07-19T19:38:46Z")

</div>

I think it is an indent issue. You assigned tableDS to an empty list and then append to it on every iteration. But you reassign it the result of the toDataSet so in the second iteration it is no longer a list, it is a DataSet.

But you probably only intended to do the toDataSet once after the loop had finished.

The moral of the story: don't reuse variables.
