# Read Data Directly From CSV

**URL:** <https://forum.inductiveautomation.com/t/read-data-directly-from-csv/15854>\
**Category:** Ignition\
**Created:** [November 2, 2017, 12:01pm UTC](https://forum.inductiveautomation.com/t/read-data-directly-from-csv/15854 "2017-11-02T12:01:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![focusengsk](https://avatars.discourse-cdn.com/v4/letter/f/46a35a/32.png) [@focusengsk](https://forum.inductiveautomation.com/u/focusengsk)\
**Post date:** [November 2, 2017, 12:01pm UTC](https://forum.inductiveautomation.com/t/read-data-directly-from-csv/15854/1 "2017-11-02T12:01:53Z")

</div>

Is it possible to read data from specific rows on a csv file, without first importing it into Ignition? Importing is a problem as it’s a file being written daily, and the export from the other system doesn’t allow formatting.  
What i need to get is compare current user logged in against username column in csv dataset and retrieve value from another column.

---

<div class="post-metadata">

**Author:** ![brandon1](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@brandon1](https://forum.inductiveautomation.com/u/brandon1)\
**Post date:** [November 2, 2017, 12:42pm UTC](https://forum.inductiveautomation.com/t/read-data-directly-from-csv/15854/2 "2017-11-02T12:42:29Z")

</div>

Why not use [system.file.readFileAsString](https://docs.inductiveautomation.com/display/DOC79/system.file.readFileAsString)?  
After you read in the file you can split the string by new line and then search through the array to find your matching username.  
This would not “import” the csv. Just reads what its current state is.

---

<div class="post-metadata">

**Author:** ![focusengsk](https://avatars.discourse-cdn.com/v4/letter/f/46a35a/32.png) [@focusengsk](https://forum.inductiveautomation.com/u/focusengsk)\
**Post date:** [November 2, 2017, 12:52pm UTC](https://forum.inductiveautomation.com/t/read-data-directly-from-csv/15854/3 "2017-11-02T12:52:02Z")

</div>

Sounds good, have you an example of how that would work? I will look into now though. Thanks!

---

<div class="post-metadata">

**Author:** ![brandon1](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@brandon1](https://forum.inductiveautomation.com/u/brandon1)\
**Post date:** [November 2, 2017, 1:06pm UTC](https://forum.inductiveautomation.com/t/read-data-directly-from-csv/15854/4 "2017-11-02T13:06:52Z")

</div>

```auto
path = system.file.openFile() # Prompt user to open a csv file
text = system.file.readFileAsString(path,"UTF-8") # Read it in as a string
rows = text.splitlines() # Split it by linefeeds into a list
# Go through the rest of the data in the file
while(i<len(rows)):
	row = rows[i]
	rawData = row.split(",") #reference columns with rawData[x]
    i++

```

---

<div class="post-metadata">

**Author:** ![focusengsk](https://avatars.discourse-cdn.com/v4/letter/f/46a35a/32.png) [@focusengsk](https://forum.inductiveautomation.com/u/focusengsk)\
**Post date:** [November 2, 2017, 1:42pm UTC](https://forum.inductiveautomation.com/t/read-data-directly-from-csv/15854/5 "2017-11-02T13:42:57Z")

</div>

had a look at the system.file.readFileAsString, and I can display it to a text area no problem, and it splits out the lines. I’m not quite sure on how filter to display row containing name of current user logged in?

---

<div class="post-metadata">

**Author:** ![brandon1](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@brandon1](https://forum.inductiveautomation.com/u/brandon1)\
**Post date:** [November 2, 2017, 2:29pm UTC](https://forum.inductiveautomation.com/t/read-data-directly-from-csv/15854/6 "2017-11-02T14:29:32Z")

</div>

You have to loop through the list of lines, and when you find the data that you want the place it in the text area.

---

<div class="post-metadata">

**Author:** ![focusengsk](https://avatars.discourse-cdn.com/v4/letter/f/46a35a/32.png) [@focusengsk](https://forum.inductiveautomation.com/u/focusengsk)\
**Post date:** [November 2, 2017, 2:47pm UTC](https://forum.inductiveautomation.com/t/read-data-directly-from-csv/15854/7 "2017-11-02T14:47:08Z")

</div>

Will keep searching, thanks for your help! Shouldn’t be too far away

---

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [November 2, 2017, 3:13pm UTC](https://forum.inductiveautomation.com/t/read-data-directly-from-csv/15854/8 "2017-11-02T15:13:48Z")

</div>

Depending on the size of the file, you would probably want to use the following code. This does not require that the whole file be read into memory, unlike the previous answer.

```auto
from __future__ import with_statement
with open(path) as f:
    for line in f:
        <do something with line>

```

---

<div class="post-metadata">

**Author:** ![focusengsk](https://avatars.discourse-cdn.com/v4/letter/f/46a35a/32.png) [@focusengsk](https://forum.inductiveautomation.com/u/focusengsk)\
**Post date:** [November 2, 2017, 3:51pm UTC](https://forum.inductiveautomation.com/t/read-data-directly-from-csv/15854/9 "2017-11-02T15:51:19Z")

</div>

Thanks Kyle, I have not seen this done before. I will have a look and see. All I have is two columns, and based on user logged in, search rows in csv and display one/or both columns. I’m sure I’ll find something suitable.
