Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Python module + Stata ado: include or import?

    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:
    Code:
    (my Stata code)
    python:
    (my Python code)
    end
    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:
    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.

  • #2
    Originally posted by Mark Schaffer View Post
    What's the better approach?
    I prefer the first one, as it keeps all the code together, making it easier to deploy and check what versions users have. But it kind of also depends on the size of the project and the size of the team. If you have a huge project with multiple developers, inevitably some of them will specialize in ado-code and some in python-code, thus favoring the second approach.

    Hope this helps.
    Best, Sergiy

    Comment


    • #3
      I use the first approach. Keeps everything together.

      Comment

      Working...
      X