<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] ## 1. @classmethod 類方法,不需要實例化對象就可以調用類方法(@classmethod修飾)和成員 ~~~ __author__ = 'dailin' class test: name="張馨予" def __init__(self,num): self.num=num print("test類初始化....") @classmethod def getTest(cls,num): print("名字是:%s"%cls.name) # 使用成員 return cls(num) # 創建對象并返回 def echoes(self): print("該Test對象的num是:%s"%(self.num)) test =test.getTest(10230) test.echoes() ~~~ 運行代碼輸出 ~~~ 名字是:張馨予 test類初始化.... 該Test對象的num是:10230 ~~~ ## 2. hasattr和getattr getattr調用方法或者導入類對象時使用 判斷對象是否具有和調用對象某個方法 引用上邊的類 ~~~ tester1 = test(41561) if(hasattr(tester1,"echos")): tester1.getattr(tester1,"echoes") ~~~ ## 3. 動態導入模塊 1. 模塊 ~~~ __author__ = 'dailin' class People: def say(self): print("hello python!") @classmethod def getPeople(cls): return cls() ~~~ 2. 導入對象的工具方法,導入類并調用類方法得到對象,然后調用對象方法 ~~~ from importlib import import_module def load_object(path): """Load an object given its absolute object path, and return it. object can be a class, function, variable or an instance. path ie: 'scrapy.downloadermiddlewares.redirect.RedirectMiddleware' """ try: dot = path.rindex('.') except ValueError: raise ValueError("Error loading object '%s': not a full path" % path) module, name = path[:dot], path[dot+1:] mod = import_module(module) # 導入模塊 try: obj = getattr(mod, name) # 導入類對象 except AttributeError: raise NameError("Module '%s' doesn't define any object named '%s'" % (module, name)) return obj import sys print(sys.path) o = load_object("Stark.sayhello.People") people = o.getPeople() # 通過類方法獲得對象實例 people.say() # 調用方法 ~~~ ~~~ ['E:\\Django\\Stark\\Arya', 'E:\\Django\\Stark', 'D:\\Python\\Python36\\python36.zip', 'D:\\Python\\Python36\\DLLs', 'D:\\Python\\Python36\\lib', 'D:\\Python\\Python36', 'D:\\Python\\Python36\\lib\\site-packages', 'D:\\Python\\Python36\\lib\\site-packages\\psutil-5.2.2-py3.6-win-amd64.egg', 'D:\\Python\\Python36\\lib\\site-packages\\helloworld-0.1-py3.6.egg', 'D:\\Python\\Python36\\lib\\site-packages\\sayhello-0.1-py3.6.egg', 'D:\\Python\\Python36\\lib\\site-packages\\win32', 'D:\\Python\\Python36\\lib\\site-packages\\win32\\lib', 'D:\\Python\\Python36\\lib\\site-packages\\Pythonwin'] hello python! ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看