当前位置: 首页>>代码示例>>Python>>正文


Python Constants.__getattribute__方法代码示例

本文整理汇总了Python中Constants.__getattribute__方法的典型用法代码示例。如果您正苦于以下问题:Python Constants.__getattribute__方法的具体用法?Python Constants.__getattribute__怎么用?Python Constants.__getattribute__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Constants的用法示例。


在下文中一共展示了Constants.__getattribute__方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_move

# 需要导入模块: import Constants [as 别名]
# 或者: from Constants import __getattribute__ [as 别名]
    def get_move (self, updates, first_move = False) :
        """ Communicate with the player code and return the move. """
        if (not first_move) :
            self.add_to_info_to_send (str (len (updates)))
            self.add_to_info_to_send (updates.to_bot_format ())
            self.add_to_info_to_send (str (self.nitro_left) + " "
                                      + str (self.traverser_left) + linesep)

        self.process.stdin.write (self.info_to_send + linesep)
        print "bot number : ", self.symbol
        print "sent message : ", self.info_to_send
        self.process.stdin.flush ()
        self.info_to_send = ""
        print "waiting for response ..."
        self.ensure_running ()
        # Now, repeatedly check whether the bot has given any
        # output until we go beyond time limit.
        output_list = []

        def put_function_output_into_list (function, list_) :
            list_.append (function ())

        output_collector = Thread (target = put_function_output_into_list,
                                   args = (self.process.stdout.readline,
                                           output_list))
        output_collector.daemon = True  
        # So the thread is killed when the program is killed
        start = datetime.now ()
        output_collector.start ()
        while (datetime.now () - start) < timedelta (0, TIMEOUT, 0) :
            if len (output_list) == 1 :
                break
            else :
                sleep (0.01)
        else :
            # Execution came here means that the player exceed time limit.
            print "player", self.symbol , "exceeded time limit."
            raise BotTimedOutError (self.symbol)

        direction = output_list[0].strip ()
        self.ensure_running ()
        print "got response : ", direction
        updates.reset ()
        try :
            return Constants.__getattribute__ (direction)
        except :
            print "Invalid move by bot number", self.symbol, ":", direction
            raise InvalidMoveError (self.symbol)
开发者ID:cegprakash,项目名称:Automania,代码行数:50,代码来源:Bot.py


注:本文中的Constants.__getattribute__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。