• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            O(1) 的小樂

            Job Hunting

            公告

            記錄我的生活和工作。。。
            <2010年10月>
            262728293012
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            統計

            • 隨筆 - 182
            • 文章 - 1
            • 評論 - 41
            • 引用 - 0

            留言簿(10)

            隨筆分類(70)

            隨筆檔案(182)

            文章檔案(1)

            如影隨形

            搜索

            •  

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            What is `if __name__ == "__main__"` for?

            轉載自http://pyfaq.infogami.com/tutor-what-is-if-name-main-for

            What is `if __name__ == "__main__"` for?

            The if __name__ == "__main__": ... trick exists in Python so that our Python files can act as either reusable modules, or as standalone programs. As a toy example, let's say that we have two files:

            mumak:~ dyoo$ cat mymath.py
            def square(x):
                return x * x
            
            if __name__ == '__main__':
                print "test: square(42) ==", square(42)
            
            
            mumak:~ dyoo$ cat mygame.py
            import mymath
            
            print "this is mygame."
            print mymath.square(17)
            

            In this example, we've written mymath.py to be both used as a utility module, as well as a standalone program. We can run mymath standalone by doing this:

            mumak:~ dyoo$ python mymath.py
            test: square(42) == 1764
            

            But we can also use mymath.py as a module; let's see what happens when we run mygame.py:

            mumak:~ dyoo$ python mygame.py
            this is mygame.
            289
            

            Notice that here we don't see the 'test' line that mymath.py had near the bottom of its code. That's because, in this context, mymath is not the main program. That's what the if __name__ == "__main__": ... trick is used for.

            posted on 2010-09-14 08:46 Sosi 閱讀(235) 評論(0)  編輯 收藏 引用

            統計系統
            一本久久免费视频| 国内精品久久久久久久久电影网 | 久久国产成人午夜aⅴ影院| 狠色狠色狠狠色综合久久| 狠狠色丁香久久综合婷婷| 亚洲国产一成久久精品国产成人综合| 亚洲国产一成人久久精品| 岛国搬运www久久| 老色鬼久久亚洲AV综合| 精品国产综合区久久久久久 | 久久91精品久久91综合| 午夜精品久久久内射近拍高清| 日本久久久久亚洲中字幕| 中文字幕无码久久精品青草| 久久免费小视频| 91精品国产乱码久久久久久| 久久人人爽人人爽人人av东京热| 天天爽天天狠久久久综合麻豆 | 久久精品aⅴ无码中文字字幕重口| 狠狠人妻久久久久久综合| 精品久久久久久成人AV| 无码人妻久久久一区二区三区 | 久久久久久青草大香综合精品| 99精品久久久久久久婷婷| 国产精品热久久无码av| 蜜臀av性久久久久蜜臀aⅴ麻豆 | 亚洲色欲久久久综合网东京热| 97精品伊人久久久大香线蕉| 狠狠干狠狠久久| 成人国内精品久久久久影院| www久久久天天com| 久久综合给合久久狠狠狠97色 | 久久久久亚洲AV无码专区桃色| 久久国产综合精品五月天| 国内精品久久久久久久97牛牛| 久久99热这里只有精品国产| 亚洲AⅤ优女AV综合久久久| 无码乱码观看精品久久| 亚洲欧洲久久久精品| 久久久久久久97| 精品国产福利久久久|