oTree Forum >

How to reuse class definition code in otree?

#1 by wying

Hi all!

I'm trying to develop my experiment in oTree. Apps with similar group definitions and pages are required.
I want to define the Group in a separate Python file and import it into the app's __init__ file.

For example, my file structure is as follows:
--myproject
----mymodel
------__init__.py
------interactiveAgg.py
----myapp
------__init__.py
and class Group is defined in interactive_agg.py
I try to use "from mymodel.interactiveAgg import Group" to import the Group class, but I fail. The error message is
ModuleNotFoundError: No module named 'interactiveAgg.models'; 'interactiveAgg' is not a package.

I wonder how to fix it or how to reuse code in otree.

Thanks for your reply.

Write a reply

Set forum username