• <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)  編輯 收藏 引用

            統計系統
            精品久久人人爽天天玩人人妻| 久久婷婷五月综合国产尤物app| 欧美日韩中文字幕久久久不卡| 久久久精品人妻一区二区三区四| 久久综合久久鬼色| 国产精品久久久久久久午夜片| 国产∨亚洲V天堂无码久久久| 亚洲∧v久久久无码精品| 一级a性色生活片久久无| 久久精品国产精品亚洲下载| 国产AV影片久久久久久| 99久久精品国产毛片| 91麻精品国产91久久久久| 久久精品夜色噜噜亚洲A∨| 久久综合狠狠综合久久激情 | 亚洲精品久久久www| 日本精品一区二区久久久| 久久精品aⅴ无码中文字字幕不卡| 久久A级毛片免费观看| 久久精品成人影院| 久久午夜羞羞影院免费观看| 亚州日韩精品专区久久久| 99久久99久久久精品齐齐 | 91精品国产综合久久香蕉| 久久婷婷五月综合国产尤物app| 免费精品99久久国产综合精品| 香蕉久久夜色精品国产2020| 国产AⅤ精品一区二区三区久久 | 精品综合久久久久久97| 久久国产乱子伦精品免费午夜| 久久精品中文无码资源站| 欧美精品国产综合久久| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 国内精品久久久久影院免费| 日韩精品久久久肉伦网站 | 久久国产成人午夜AV影院| 久久精品一区二区国产| 久久w5ww成w人免费| 精品亚洲综合久久中文字幕| 久久精品人人槡人妻人人玩AV | 久久综合久久综合九色|