#1 by Carol
Hi, Chris, Hi all, I am currently coding an experiment with app_sequence like:[instructions, trial, experiment, survey, payoff]. Since one page in trial and one page in experiment share almost the same codes, I would like to avoid replication. I referred to this post https://groups.google.com/g/otree/c/2Z3d_SStb5o, but it seems like oTree could not find the app I would like to import when using 'from experiment import *'. I am considering combining the trial app and the experiment app. However, it is ideal to keep them separate. Thank you in advance. Carol
#2
by
BonnEconLab
Here’s a minimal working example (programmed in oTree 5.10.4). It is also attached as a ZIP archive. The two relevant app folders are called zzz_import_experiment and zzz_import_trial ============================================= Contents of zzz_import_experiment/__init__.py ============================================= from otree.api import * doc = """ The real thing. """ class C(BaseConstants): NAME_IN_URL = 'zzz_import_experiment' PLAYERS_PER_GROUP = None NUM_ROUNDS = 3 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): some_input = models.StringField() # PAGES class MyPage(Page): form_model = 'player' form_fields = ['some_input'] pass page_sequence = [ MyPage, ] ======================================== Contents of zzz_import_trial/__init__.py ======================================== from otree.api import * from zzz_import_experiment import * doc = """ Trial rounds. """ class C(C): NAME_IN_URL = 'zzz_import_trial' NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): some_input = models.StringField()
#3 by Carol
Thank you for your reply! It now works well.