Skynet

          ---------- ---------- 我的新 blog : liukaiyi.cublog.cn ---------- ----------

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            112 Posts :: 1 Stories :: 49 Comments :: 0 Trackbacks

          代碼
          參考:http://www.python.org/dev/peps/pep-0318/
          def singleton(cls):
              instances 
          = {}
              
          def getinstance():
                  
          if cls not in instances:
                  
          print "new"
                      instances[cls] 
          = cls()
                  
          return instances[cls]
              
          return getinstance

          @singleton
          class MyClass:
              
          pass


          x1
          =MyClass()
          #print new
          x2=MyClass()




          整理 www.aygfsteel.com/Good-Game
          posted on 2009-04-16 23:20 劉凱毅 閱讀(1046) 評論(0)  編輯  收藏 所屬分類: python
          主站蜘蛛池模板: 涿州市| 阆中市| 开封市| 鄄城县| 县级市| 钟山县| 化州市| 东兰县| 古丈县| 睢宁县| 佛学| 江津市| 陆丰市| 新疆| 元朗区| 辛集市| 恩平市| 佛教| 新蔡县| 房山区| 高邮市| 仁化县| 台北市| 乌拉特前旗| 西乌| 文化| 郓城县| 绵竹市| 宣汉县| 广西| 静乐县| 金坛市| 虎林市| 龙游县| 仙居县| 大兴区| 合江县| 沅江市| 阿鲁科尔沁旗| 宁安市| 辽源市|