• <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年8月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            統計

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

            統計系統
            777久久精品一区二区三区无码| 午夜精品久久久久久99热| 精品久久久久久无码中文字幕| 91精品国产高清久久久久久国产嫩草 | 国产精品久久婷婷六月丁香| 亚洲精品无码久久久久sm| 久久线看观看精品香蕉国产| 人妻中文久久久久| 久久精品国产69国产精品亚洲| 久久久久亚洲AV综合波多野结衣| 日产精品久久久一区二区| 久久成人精品| 91久久香蕉国产熟女线看| 亚洲人成精品久久久久| 老司机午夜网站国内精品久久久久久久久| 亚洲中文字幕无码久久精品1| 久久一区二区三区99| 狠狠狠色丁香婷婷综合久久俺| 精品国产乱码久久久久久呢 | 伊人色综合久久天天人手人婷| 精品久久久久中文字幕一区| 成人资源影音先锋久久资源网| 综合久久国产九一剧情麻豆| 亚洲伊人久久综合中文成人网| 91久久精品无码一区二区毛片| 国产精品青草久久久久婷婷| 亚洲va久久久噜噜噜久久天堂| 久久久黄色大片| 狠狠色丁香婷婷久久综合| 香蕉aa三级久久毛片| 99久久无码一区人妻| 久久九九青青国产精品| 亚洲国产精久久久久久久| 久久91精品国产91久久小草| 国产欧美久久久精品| 亚洲精品国产成人99久久| 91精品日韩人妻无码久久不卡| 国内精品久久久久久久coent| 精品水蜜桃久久久久久久| 亚洲精品tv久久久久| 国内精品久久国产|