I’d like to get the opinion of the Python gurus as to the correct way to handle this. I think I might be over-complicating it.
Say I have Script A that returns a value. Could be a boolean, could be a numeric value, whatever. I want to run Script A inside Script B, but I want that value to be passed from Script A to Script B when Script B runs.
What is the correct Pythonese way of handling this?
Wasn’t there something about “reload modules” instead of resetting the script engine? ISTR something like that, but I never use scripts in this way, so no personal experience…
The script runs fine as a script, but as soon as I compile it into my plug-in, it fails. I think I could probably avoid a lot of grief by just making the first script a function in the second and not try to link them.
But just for my own education I’m open to any ideas as to why the compiled script fails. BTW… I followed Javier’s example which works well as script.
It depends what you mean by saying it fails. For me, Javier’s code did not solve the problem of running stale code, only an explicit call to reload(script_a) did. But if you mean some other general failure, then I guess it would be related to how compiled scripts are unpacked for running.
As for folding both functions into a single script, that sounds like a fine idea, if there is not a compelling reason to have them separated – maybe your project is complicated enough to justify the time spent to make it work (provided there is not some technical reason it can’t), but otherwise, the value of minimizing dependencies should also not be underestimated.
I’ve put it all together in one script and it’s working well. My initial idea was to take an existing script that was already in use and have it run as a function of another. But taking the easy way out didn’t work out so well. I appreciate your help.