Trying to open and read a csv file from Python. Program works fine when run locally. However, when run from controller (execute python file via PLC) looks like the path for the csv file is wrong. Any suggestions? I also tried absolute path and also added activeconfiguration to the relative path. no luck.
Solved! Go to Solution.
The PLC side is fine. I can execute any python file. The issue is when the python file tries to read or write another file. in this case csv file.
When using the play button you mentioned the script is only run locally in the IDE. So your path is not known by the script instance when run on the ctrlX CORE.
You can also start the script in an interpreter instance by using the debugger (e.g. for testing before using the PLC for starting). See my working example for reading and writing:
FileName1 = "/var/snap/rexroth-solutions/common/solutions/activeConfiguration/tiger/projects/CsvReadWrite/csvdata1.csv" FileName2 = "/var/snap/rexroth-solutions/common/solutions/activeConfiguration/tiger/projects/CsvReadWrite/csvdata2.csv" file1 = open(FileName1,"r") file2 = open(FileName2,"w") for x in file1: data = x.split(",") for y in data: print(y) file2.write(y + ",") file1.close() file2.close()