# Issue with script to read CSV into table

**URL:** <https://forum.inductiveautomation.com/t/issue-with-script-to-read-csv-into-table/97160>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [October 11, 2024, 8:17am UTC](https://forum.inductiveautomation.com/t/issue-with-script-to-read-csv-into-table/97160 "2024-10-11T08:17:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maria\_P](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@Maria\_P](https://forum.inductiveautomation.com/u/Maria_P)\
**Post date:** [October 11, 2024, 8:17am UTC](https://forum.inductiveautomation.com/t/issue-with-script-to-read-csv-into-table/97160/1 "2024-10-11T08:17:00Z")

</div>

I'm trying this code to import data from csv into database and works fine.  
I don't need to populate a table with the data, so I'm trying to avoid this step, but there is an error I can't solve. This is the code:

```python
#1. Read data
csvData = csv.reader(open(system.file.openFile('csv')))
#2. Populate table with data
event.source.parent.getComponent('Table').data = system.dataset.toDataSet(csvData.next(), list(csvData))

# Create a dataset with the header and the rest of our CSV.
dataset1 = event.source.parent.getComponent('Table').data
dataset2 = system.dataset.toDataSet(csvData.next() ,list(csvData))

```

dataset1 and dataset2 should be the same, as I assign in point 2 the data from csv.  
but creating dataset2 shows this error:  
`Caused by: org.python.core.PyException: StopIteration`

Do you know why two datasets are not equal? I think I'm missing something.

thanks!

---

<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:** [October 11, 2024, 5:23pm UTC](https://forum.inductiveautomation.com/t/issue-with-script-to-read-csv-into-table/97160/2 "2024-10-11T17:23:45Z")

</div>

CSV reader objects are stateful. The first time, you call next() to get the header row, then you call list() which consumes the rest of the CSV document.

Then you try to do it a second time, but the reader has already given you all it can - that's why you're getting a StopIteration error.
