Announcement: New format for Constants (e.g. C.NUM_ROUNDS)

147 views
Skip to first unread message

Chris @ oTree

unread,
Dec 18, 2021, 1:34:31 PM12/18/21
to oTree help & discussion
Hi all,

In 1 week, the oTree documentation and sample games will be updated with a new format for defining constants. It will look like this:

class C(BaseConstants):
    NAME_IN_URL = 'public_goods_simple'
    PLAYERS_PER_GROUP = 3
    NUM_ROUNDS = 1
    XYZ = 42

# Then to reference a constant, do this:
C.XYZ
C.NUM_ROUNDS

So basically, the name "Constants" changes just to "C", and constants should be written in all caps.

If you have oTree 5.4 (September 2021) or higher, then it is already compatible with the new format. The existing format will continue to work.

The purpose of the change is to harmonize oTree's code style, especially in preparation for upcoming features. (Also, if you have prior experience in Python, you know that ALL_CAPS is the convention for defining constants.)

If you use oTree Studio, your code will be automatically upgraded to the new format. If you haven't upgraded oTree recently, run "pip3 install -U otree".

Thanks,
Chris

Chris @ oTree

unread,
Dec 24, 2021, 5:32:34 PM12/24/21
to oTree help & discussion
Hi all, I have published these changes live. More details here: https://otree.readthedocs.io/en/master/misc/newconstants.html

Renee

unread,
Dec 26, 2021, 8:02:20 PM12/26/21
to oTree help & discussion
Hi Chris,

Thanks for the update!

I followed the documentations to update my existing projects to the new format. After running otree upcase_constants, I got the this warning: Before running this command, you need to run "pip3 install -U black rope" 

Is this normal for the update?

Thank you in advance for any help you are able to provide!

Best,
Renee

Chris @ oTree

unread,
Dec 26, 2021, 8:16:15 PM12/26/21
to Renee, oTree help & discussion
Oh good catch! I will fix that. Though it is fine to run that command, it will get it to work until I publish a fix.

Sent from my phone

On Dec 26, 2021, at 8:02 PM, Renee <yan.s...@gmail.com> wrote:

Hi Chris,
--
You received this message because you are subscribed to a topic in the Google Groups "oTree help & discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/otree/A8cxpz6sXl0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to otree+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/b71ac920-3ac9-4bff-b2cf-822d3cc2113dn%40googlegroups.com.

Renee

unread,
Dec 26, 2021, 8:17:27 PM12/26/21
to oTree help & discussion
Thank you Chris!
Reply all
Reply to author
Forward
0 new messages