¿ªÔÆÌåÓý

Closing a CSV file within script


 

I have a script which reads a CSV file created within Excel to automate my layout.
Each row in the file describes a section in the layout such as blocks, sensors, turnouts, turnout state, signal etc.
?
Path to the file is self.routeSelFile = (self.retval+"/Routes/Live/"+self.filename) - I run this on two PCs (not concurrently) and self.retval is the path for a specific PC, self.filename is the route selection from a drop-down.
File is opened with self.sens_file = open(self.routeSelFile, "r")
And closed when the script terminates with? self.sens_file.close()
There are other clean up routines called when the script terminates with status messages so I am confident the close() is being performed.
?
The script works fine (although lots of functionality still in development) and I run an instance (if that's the correct word) of the script to control each loco.
?
When open a CSV file using Excel due to a typo or modification if that file has been previously opened by a script Excel will not allow me to save the updated CSV file with the same name, it states that someone else is using the file and offers to save a copy or cancel.
It does not come up with the usual Excel message of "open in read only" when I open the file or any other warning, only when I try to save it.
?
This is the case even if I just run one instance of the script and then terminate it properly.
There is no error message in the console.
?
I can save the CSV file with the same name and no error if I quit PanelPro
?
I wonder if there is something that I should also be doing in Windows to reset a flag or something else?
?
Any advice welcome, thanks
Pete
?
PanelPro 5.8+Rbc21ce2ce
Java 11.0.13
Windows 10 Pro 64
Excel 2019
?
?
?


 

Is it possible that you¡¯re accidentally opening the file twice?

Do I understand correctly that you only see the problem if PanelPro is still running, and the problem doesn¡¯t occur if you¡¯ve quit PanelPro?

Bob

On May 9, 2025, at 9:16?AM, Peter Lambert via groups.io <peterlambert789@...> wrote:

I have a script which reads a CSV file created within Excel to automate my layout.
Each row in the file describes a section in the layout such as blocks, sensors, turnouts, turnout state, signal etc.
Path to the file is self.routeSelFile = (self.retval+"/Routes/Live/"+self.filename) - I run this on two PCs (not concurrently) and self.retval is the path for a specific PC, self.filename is the route selection from a drop-down.
File is opened with self.sens_file = open(self.routeSelFile, "r")
And closed when the script terminates with self.sens_file.close() There are other clean up routines called when the script terminates with status messages so I am confident the close() is being performed.
The script works fine (although lots of functionality still in development) and I run an instance (if that's the correct word) of the script to control each loco.
When open a CSV file using Excel due to a typo or modification if that file has been previously opened by a script Excel will not allow me to save the updated CSV file with the same name, it states that someone else is using the file and offers to save a copy or cancel.
It does not come up with the usual Excel message of "open in read only" when I open the file or any other warning, only when I try to save it.
This is the case even if I just run one instance of the script and then terminate it properly.
There is no error message in the console.
I can save the CSV file with the same name and no error if I quit PanelPro
I wonder if there is something that I should also be doing in Windows to reset a flag or something else?
Any advice welcome, thanks
Pete
PanelPro 5.8+Rbc21ce2ce
Java 11.0.13
Windows 10 Pro 64
Excel 2019
¡ª
Bob Jacobsen
rgj1927@...


 

Thanks for the prompt reply.
I have tested this on a third PC but not connected to the layout, run the script as normal but set sensors manually as if the loco is running on the layout,
The same configuration and versions as the other PCs and it is ok, I can save the updated CSV even if it is still open in the script.
?
The only difference I can think of is that the PCs I use to control the layout access files via a network, the PC where it works is also the network server.
?
All PCs run their local JMRI, same versions of JMRI, Java, Excel and Windows and as far as I can see, the same settings.
?
Put this on the back burner while I go through some sort of process of elimination but it does not seem to be a JMRI problem unless there is something under the hood regarding file locking but I cannot see anything in settings.
?
To answer you question, yes I only see the problem while PanePro is running, I can save the CSV file with the same name by quitting PanelPro.
?
Thanks
Pete