__name__ is the name of the current app

292 views
Skip to first unread message

Candy F

unread,
Nov 10, 2021, 10:28:43 PM11/10/21
to oTree help & discussion
Hi Chris and all, I am having a question with a line of code at Otree snippets:
It is pay_random_app1

class Constants(BaseConstants):
name_in_url = 'pay_random_app1'
players_per_group = None
num_rounds = 1

class ResultsWaitPage(WaitPage):
@staticmethod
def after_all_players_arrive(group: Group):
"""
In multiplayer games, payoffs are typically set in after_all_players_arrive,
so that's what we demonstrate here.
"""
import random

for p in group.get_players():
participant = p.participant
potential_payoff = random.randint(100, 200)
p.potential_payoff = potential_payoff
# __name__ is the name of the current app
participant.app_payoffs[__name__] = potential_payoff

I am wondering what to put in that name part. Is it:
participant.app_payoffs[__pay_random_app1__] = potential_payoff

Because when I am running my own code(participant.app_payoffs[__ABC__] = potential_payoff)
 I have an Attribution error that said participant field does not have the field ABC so I am wondering if I am understanding the model code correctly(maybe I did something wrong somewhere else, just trying to figure things out).

Thanks!

Candy F

unread,
Nov 10, 2021, 10:56:55 PM11/10/21
to oTree help & discussion
Application error (500)AttributeError: 'Participant' object has no attribute 'app_payoffs'

Chris @ oTree

unread,
Nov 10, 2021, 10:58:40 PM11/10/21
to Candy F, oTree help & discussion
__name__ is already an automatic Python variable containing the name of the current app. You don’t need to change it. You can find more info on google.  

Sent from my phone

On Nov 11, 2021, at 4:28 AM, Candy F <cf05...@gmail.com> wrote:


--
You received this message because you are subscribed to the Google Groups "oTree help & discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to otree+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/85837687-d90e-40a1-9495-928190ce5310n%40googlegroups.com.

Candy F

unread,
Nov 10, 2021, 11:31:16 PM11/10/21
to oTree help & discussion
Thank you Chris : )
Reply all
Reply to author
Forward
0 new messages