oTree Forum >

Understanding rationale behind two different sets of codes

#1 by AB_123

Hi there,

Hope you are well. I am just trying to understand if I am on the right path and the rationale behind my codes are correct. I tried online platforms and also tested my codes in different ways, without any clear-cut answers. Hence, my questions to you.

So, my code player allocation into groups is:

class Subsession(BaseSubsession):
    pass


def creating_session(subsession: Subsession):
    subsession.group_randomly()

Often people use:
 def creation_session(self):
     self.group_randomly()
What is the difference between my approach and this use of self?

#2 by FEDx

"self." is an old pre-2021 syntax since everything was unified. In fact, quote:
As of 2021, a new optional format has been introduced for oTree applications. It replaces models.py and pages.py with a single __init__.py.
The new format unifies the syntax of oTree. For example, before you had to write player.payoff, self.payoff or self.player.payoff, depending on what part of the code you were in. Now you can always write player.payoff. In fact, the self keyword has been eliminated altogether.

Use your subsession.group_randomly(), that's the correct one. I add that, the code you posted with self. is on a player basis, yours is on a session basis, quite a big difference.

#3 by AB_123

@FEDx: Thank you so much.

Write a reply

Set forum username