#1
by
AndreL
(edited )
In the official documentation, there is this suggested code snippet for oTree Lite
(https://otree.readthedocs.io/en/latest/timeouts.html?highlight=get_timeout_seconds#get-timeout-seconds)
===========================================
class Start(Page):
@staticmethod
def before_next_page(player, timeout_happened):
participant = player.participant
import time
# remember to add 'expiry' to PARTICIPANT_FIELDS.
participant.expiry = time.time() + 5*60
============================================
Is there any particular reason that one could not write simply as below? Is there any obscure advantage from defining the participant instance explicitly?
===========================================
class Start(Page):
@staticmethod
def before_next_page(player, timeout_happened):
import time
player.participant.expiry = time.time() + 5*60
============================================
Also, is there any impact whatsoever whether import time is appended at the top of ___init___.py, or within the function as above?
#2
by
Chris_oTree
It's the same thing. But as your code gets longer, you will see it's more concise to define participant = player.participant once at the top. As for the import, it's the same thing either way.