Export/Import csv questions

I am trying out new things as I learn Ignition/Python and today I was playing around with the .exportCSV command. The command worked fine, and I followed the example found within the user manual, but at the end of the script I believe it’s trying to make it automatically open the document, and I’m getting an error. My code is:

table = event.source.parent.getComponent(‘Table’)
filePath = system.dataset.exportCSV(“IgnitionTest.csv” , 1, table.data)
if filePath != None:
system.net.openURL(“file://”+filePath)

And the error is:

URISyntaxException: Illegal character in authority at index 7: [file://C](file://C):\Users\Alex\Desktop\IgnitionTest.csv

Ignition v7.7.5 (b2015071516)
Java: Oracle Corporation 1.8.0_45

I’m not sure what the illegal character in authority at index 7 means? :question: Any insight to something like this?

Also, I do not see an import command. How would one import a csv file? is there a .importCSV command not listed in the user manual? Thanks in advance for the help! :thumb_left:

Somewhere along the way, Java’s URI handling changed to something a bit more strict.

Try replacing:

if filePath != None: system.net.openURL("file://"+filePath)

with this:

if filePath != None: filePath = filePath.replace(' ', '%20') filePath = filePath.replace('\\', '/') system.net.openURL("file:" + filePath)

That worked perfectly!!! What exactly is going on with that code? Lots of slashes and quotes going on there. So that’s one question answered! Now, how to import stuff. Any takers?

Spaces and backslashes are not supported characters for a URI. So the spaces get replaced by %20, the Hex ASCII equivalent. You may have noticed it used in your web browser address bar.

Backslashes are bit more complex. in Python, a backslash is used for special characters. Example, '\n' is a newline. If you actually need a backslash character, you would use a double-backslash. How's that for mud in the water? :laughing:


For handling CSV, take a look at this thread

Ok, I think the spaces and black slashes issues are pretty clear :thumb_left:

While that CSV help forum is helpful I think it left me even more confused :scratch: I was wanting to use the .readFileAsString command and it keeps returning the error:

Traceback (most recent call last):

File “event:actionPerformed”, line 4, in

IOError: File ‘C:\Users\Alex\Desktop\Tags’ doesn’t exist or isn’t a file.

The code I’m using in this application for this button is:

fileName=event.source.parent.getComponent(‘Text Field’).text
path = system.file.openFile

textarea= system.file.readFileAsString(“C:\Users\Alex\Desktop\”+fileName)

event.source.parent.getComponent(‘Text Area’).text = textarea

Am I way off the reservation with this or am I pretty close, just missing it by that much? :laughing: The help so far has been astounding and greatly appreciated!

Let's start here:

Is the filename just 'Tags'? You likely have an extension on the filename, like 'Tags.csv'. If so, that's where the issue is. :slight_smile:

Accolades all around! That solved it good sir!!! :prayer: :thumb_right:

Glad I could help, Alex!