Read Data Directly From CSV

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.

Why not use 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.

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

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
	row = rows[i]
	rawData = row.split(",") #reference columns with rawData[x]

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?

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.

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

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.

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

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.