I’m posting this here rather than on the PyHamilton part of the forums due to the fact that I’m not actually using the PyHamilton software at the moment (due to work related IT issues). I have written a python script that reads a file, takes an input from that file, and then writes to another separate file. When I run the python script on its own it runs perfectly fine. Within the Hamilton Method Editor, I call the python script, which works fine, but when it runs the script, it seems to only be able to read files and not write to them. I’m assuming this is a permissions issue, but I’m having trouble finding out where to fix it; any help would be greatly appreciated.
I am not 100% certain that it is reading the file but I think its managing as it seems to read and split a string from a file, but then just doesn’t write to the csv that I want it to. The csv is meant to act as a check that a subsequent file-read is valid (essentially to check that the file I want it to read is of the right type). The aim is that it reads a file path, goes to check if the file a) exists and b) is of the right format, then writes to another file whether it is or isn’t valid, which is then read by Venus so that it gets the user to try put in a new input file rather than crashing with an error that “database or object is read only”, which I assume is because it’s trying to read it as though its a CSV when its being given a pdf/anything else.
Put a bunch of print statements (or logging outputs) in the python script so you can tell what line its getting to, and other data like current working directory. It could be hitting an error that isn’t getting sent back up to Venus.
This might be a stupid question but where do I view print statements when I call it through venus? Obviously when I run the script on its own I can see it in the shell, but I don’t know where it would print to when being called from Venus.
Thanks to you all! In the end I managed to do the part I was having difficulty with without using python. In case anyone has a similar issue: instead I used StrFind from HSLStrLib and looked for a substring of the file extension with the variable, in my case “.csv”. Not bulletproof but good enough to prevent accidents for what I’ll be doing at least.
I had troubles knowing why the application in FluentControl fails as the window closes immediately. So, I added logging (python library) to the .exe that it writes an extra log file, so you can manage to traceback the error history or information you are printing. (log.info(“…”) instead of print(“…”)). Then you at least know whats going on. Also, you can store the return value of each application. A return value of 0 means it succeeded, and 1 means it failed.
Another trick I’ve used for debugging scripts initiated through Venus is to sprinkle
in as pseudo break-points. You’ll be able to read all of the print statements up to that point as well because the input step blocks Venus from closing the window. Can help narrow down where your program is failing. Just make sure that your window isn’t set to be minimized in the shell command through Venus and you should be able to see it.