• <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 閱讀(228) 評論(0)  編輯 收藏 引用

            統計系統
            久久亚洲AV无码精品色午夜| 国内精品久久久久影院优| 国产高潮国产高潮久久久91| 69SEX久久精品国产麻豆| 51久久夜色精品国产| 国产精品美女久久福利网站| av色综合久久天堂av色综合在| 久久国产色AV免费看| 久久精品不卡| 中文精品久久久久国产网址| 欧美粉嫩小泬久久久久久久| 久久精品亚洲日本波多野结衣| 久久精品亚洲精品国产欧美| 亚洲精品无码久久久久去q| 国内精品久久久久久久影视麻豆| 久久精品国产2020| 久久国产成人| 久久综合九色综合久99| 一本色道久久HEZYO无码| 日韩va亚洲va欧美va久久| 国内精品久久久久影院优| 久久久久国产精品人妻| 久久精品国产99国产精品| 久久亚洲私人国产精品| 伊人伊成久久人综合网777| 777久久精品一区二区三区无码| 久久婷婷五月综合色奶水99啪| 国产精品久久久久免费a∨| 免费一级做a爰片久久毛片潮 | 精品国产综合区久久久久久| 久久久精品国产sm调教网站 | 久久国产香蕉一区精品| 99久久人妻无码精品系列| 久久精品中文无码资源站| 国产毛片欧美毛片久久久| 精品伊人久久久| 久久综合鬼色88久久精品综合自在自线噜噜| www.久久热| 91精品国产91久久久久久青草| 国产精品国色综合久久| 精品一区二区久久久久久久网站|