Hi everybody. I have a Stata + Python coding style question. It's prompted by an obscure bug I'm having trouble tracking down, but maybe it's of general interest.
I have a Stata ado that uses a dedicated block of Python code. There's two ways to organize this:
1. Standard - include the Python code inside the ado file in the usual way:
2. Split - have separate .ado and .py files in the same location. The file mypythoncode.py (say) has pure Python code, and the ado tells Python to import the code:
What's the better approach?
FWIW ... there was an obscure bug a while ago that showed up with method 1 but not with method 2, so we switched to using method 2. Then a Stata update fixed that obscure bug. Now we've run into a different obscure bug ("ModuleNotFoundError: No module named 'mypythoncode'") and I am wondering whether switching back to method 1 would fix it. "Obscure bug" = I can't reproduce it, and I know about it only via others who are using the ado. The second bug can be fixed by uninstalling the ado, exiting Stata, re-entering Stata and reinstalling the ado ... but that's a bit of a hassle. And once it's fixed, the bug is no longer reproducible.
I have a Stata ado that uses a dedicated block of Python code. There's two ways to organize this:
1. Standard - include the Python code inside the ado file in the usual way:
Code:
(my Stata code) python: (my Python code) end
Code:
(my Stata code) python: from mypythoncode import *
What's the better approach?
FWIW ... there was an obscure bug a while ago that showed up with method 1 but not with method 2, so we switched to using method 2. Then a Stata update fixed that obscure bug. Now we've run into a different obscure bug ("ModuleNotFoundError: No module named 'mypythoncode'") and I am wondering whether switching back to method 1 would fix it. "Obscure bug" = I can't reproduce it, and I know about it only via others who are using the ado. The second bug can be fixed by uninstalling the ado, exiting Stata, re-entering Stata and reinstalling the ado ... but that's a bit of a hassle. And once it's fixed, the bug is no longer reproducible.
Comment