久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      <small id='8v5oA'></small><noframes id='8v5oA'>

    1. <i id='8v5oA'><tr id='8v5oA'><dt id='8v5oA'><q id='8v5oA'><span id='8v5oA'><b id='8v5oA'><form id='8v5oA'><ins id='8v5oA'></ins><ul id='8v5oA'></ul><sub id='8v5oA'></sub></form><legend id='8v5oA'></legend><bdo id='8v5oA'><pre id='8v5oA'><center id='8v5oA'></center></pre></bdo></b><th id='8v5oA'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='8v5oA'><tfoot id='8v5oA'></tfoot><dl id='8v5oA'><fieldset id='8v5oA'></fieldset></dl></div>
        <bdo id='8v5oA'></bdo><ul id='8v5oA'></ul>
        <legend id='8v5oA'><style id='8v5oA'><dir id='8v5oA'><q id='8v5oA'></q></dir></style></legend><tfoot id='8v5oA'></tfoot>
      1. 如何觸發價值變化的功能?

        How to trigger function on value change?(如何觸發價值變化的功能?)
          <tbody id='nFoIZ'></tbody>
          <bdo id='nFoIZ'></bdo><ul id='nFoIZ'></ul>

          <i id='nFoIZ'><tr id='nFoIZ'><dt id='nFoIZ'><q id='nFoIZ'><span id='nFoIZ'><b id='nFoIZ'><form id='nFoIZ'><ins id='nFoIZ'></ins><ul id='nFoIZ'></ul><sub id='nFoIZ'></sub></form><legend id='nFoIZ'></legend><bdo id='nFoIZ'><pre id='nFoIZ'><center id='nFoIZ'></center></pre></bdo></b><th id='nFoIZ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='nFoIZ'><tfoot id='nFoIZ'></tfoot><dl id='nFoIZ'><fieldset id='nFoIZ'></fieldset></dl></div>

          1. <small id='nFoIZ'></small><noframes id='nFoIZ'>

                <legend id='nFoIZ'><style id='nFoIZ'><dir id='nFoIZ'><q id='nFoIZ'></q></dir></style></legend>
                • <tfoot id='nFoIZ'></tfoot>
                  本文介紹了如何觸發價值變化的功能?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我意識到這個問題與事件處理有關,并且我已經閱讀了有關 Python 事件處理程序和調度程序的信息,所以要么它沒有回答我的問題,要么我完全錯過了信息.

                  I realise this question has to do with event-handling and i've read about Python event-handler a dispatchers, so either it did not answer my question or i completely missed out the information.

                  我希望在值 v 發生變化時觸發對象 A 的方法 m():

                  I want method m() of object A to be triggered whenever value v is changing:

                  例如(假設金錢使人快樂):

                  For instance (assuming money makes happy):

                  global_wealth = 0
                  
                  class Person()
                      def __init__(self):
                          self.wealth = 0
                          global global_wealth
                          # here is where attribute should be
                          # bound to changes in 'global_wealth'
                          self.happiness = bind_to(global_wealth, how_happy)
                  
                      def how_happy(self, global_wealth):
                          return self.wealth / global_wealth
                  

                  因此,每當 global_wealth 值更改時,Person 類的所有實例都應相應更改其 happiness 值.

                  So whenever the global_wealth value is changed, all instances of the class Person should change their happiness value accordingly.

                  NB:我不得不編輯這個問題,因為第一個版本似乎表明我需要 getter 和 setter 方法.很抱歉造成混亂.

                  NB: I had to edit the question since the first version seemed to suggest i needed getter and setter methods. Sorry for the confusion.

                  推薦答案

                  你需要使用 觀察者模式.在以下代碼中,一個人訂閱接收來自全球財富實體的更新.當全球財富發生變化時,該實體會提醒其所有訂閱者(觀察者)發生變化.Person 然后更新自己.

                  You need to use the Observer Pattern. In the following code, a person subscribes to receive updates from the global wealth entity. When there is a change to global wealth, this entity then alerts all its subscribers (observers) that a change happened. Person then updates itself.

                  我在這個例子中使用了屬性,但它們不是必需的.一個小警告:屬性僅適用于新樣式類,因此類聲明后的 (object) 是強制性的.

                  I make use of properties in this example, but they are not necessary. A small warning: properties work only on new style classes, so the (object) after the class declarations are mandatory for this to work.

                  class GlobalWealth(object):
                      def __init__(self):
                          self._global_wealth = 10.0
                          self._observers = []
                  
                      @property
                      def global_wealth(self):
                          return self._global_wealth
                  
                      @global_wealth.setter
                      def global_wealth(self, value):
                          self._global_wealth = value
                          for callback in self._observers:
                              print('announcing change')
                              callback(self._global_wealth)
                  
                      def bind_to(self, callback):
                          print('bound')
                          self._observers.append(callback)
                  
                  
                  class Person(object):
                      def __init__(self, data):
                          self.wealth = 1.0
                          self.data = data
                          self.data.bind_to(self.update_how_happy)
                          self.happiness = self.wealth / self.data.global_wealth
                  
                      def update_how_happy(self, global_wealth):
                          self.happiness = self.wealth / global_wealth
                  
                  
                  if __name__ == '__main__':
                      data = GlobalWealth()
                      p = Person(data)
                      print(p.happiness)
                      data.global_wealth = 1.0
                      print(p.happiness)
                  

                  這篇關于如何觸發價值變化的功能?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機器人?)
                  Discord bot isn#39;t responding to commands(Discord 機器人沒有響應命令)
                  Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關于我嗎?Discord 機器人的功能?(不和諧.py))
                  message.channel.id Discord PY(message.channel.id Discord PY)
                  How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機器人?)
                  discord.py - Automaticaly Change an Role Color(discord.py - 自動更改角色顏色)
                    <bdo id='xI4ns'></bdo><ul id='xI4ns'></ul>
                      <tbody id='xI4ns'></tbody>
                    <i id='xI4ns'><tr id='xI4ns'><dt id='xI4ns'><q id='xI4ns'><span id='xI4ns'><b id='xI4ns'><form id='xI4ns'><ins id='xI4ns'></ins><ul id='xI4ns'></ul><sub id='xI4ns'></sub></form><legend id='xI4ns'></legend><bdo id='xI4ns'><pre id='xI4ns'><center id='xI4ns'></center></pre></bdo></b><th id='xI4ns'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='xI4ns'><tfoot id='xI4ns'></tfoot><dl id='xI4ns'><fieldset id='xI4ns'></fieldset></dl></div>

                    • <legend id='xI4ns'><style id='xI4ns'><dir id='xI4ns'><q id='xI4ns'></q></dir></style></legend>

                      1. <tfoot id='xI4ns'></tfoot>

                          1. <small id='xI4ns'></small><noframes id='xI4ns'>

                          2. 主站蜘蛛池模板: 人人射人人 | 波多野结衣亚洲 | 黄色av网站免费看 | 中文字幕精品一区 | 亚洲国产欧美日韩 | 日韩成人在线一区 | 免费国产一区二区视频 | 三级特黄特色视频 | 亚洲一区精品在线 | 日本精品一区二区三区在线观看视频 | 古典武侠第一页久久777 | 精品国产一区二区在线 | 国产精品乱码一二三区的特点 | 亚洲一区视频在线 | 久久精品国产一区二区电影 | 久久亚洲一区 | 美女拍拍拍网站 | 午夜影视免费片在线观看 | www.99re| 成人在线电影网站 | www.亚洲精品| 在线观看成年人视频 | 午夜小电影 | 黄色大全免费看 | 午夜视频在线 | 9999精品视频 | 美国黄色毛片 | 综合色站导航 | 亚洲一区二区三区乱码aⅴ 四虎在线视频 | 91pron在线 | 成年人视频在线免费观看 | 天天综合网永久 | 99热成人在线 | 一级毛片视频在线观看 | 黄色av网站在线观看 | 亚洲天堂久久 | 亚洲一区二区三区在线播放 | 日韩欧美一区二区三区免费观看 | 亚洲精品久久久一区二区三区 | 日本亚洲欧美 | 一区二区三区精品视频 |