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 劉凱毅 閱讀(1050) 評論(0)  編輯  收藏 所屬分類: python
          主站蜘蛛池模板: 图木舒克市| 响水县| 丘北县| 房山区| 辽宁省| 西充县| 博兴县| 得荣县| 陵川县| 海阳市| 龙泉市| 铜山县| 文登市| 浠水县| 耒阳市| 阳江市| 扶绥县| 平昌县| 偃师市| 连云港市| 武陟县| 霞浦县| 阜新| 湖南省| 永定县| 康马县| 上高县| 黔西| 进贤县| 白水县| 孟津县| 景谷| 大丰市| 梁平县| 涞水县| 方正县| 滨海县| 临邑县| 建瓯市| 甘孜县| 大渡口区|