Filepath Multiple Backslashes in String

import csv
filename = "C:\Users\image\Desktop\test.csv"
print(filename)
with open(filename) as csvfile:
	readCSV = csv.reader(csvfile, delimiter=',')

print returns “C:\Users\image\Desktop\test.csv”

but I get an error

12:50:52.160 [AWT-EventQueue-0] ERROR com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter - <HTML>Error executing script for event:&nbsp;<code><b>actionPerformed</b></code><BR>on component:&nbsp;<code><b>Button 1</b></code>.
com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last):
  File "<event:actionPerformed>", line 43, in <module>
IOError: (2, 'No such file or directory', 'C:\\Users\\image\\Desktop\\test.csv')

The file does exist and is at that location.Not sure why the error returns with double back slashes but the print does not. I’ve tried putting an r before the string and using double backslashes within the string.

Simplest thing to try: just use forward slashes. Python’s usually pretty forgiving about allowing them.

2 Likes