• <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嫖农村妇女| 一本久久a久久精品亚洲| 久久99国产精品尤物| 97精品国产91久久久久久| 青青青伊人色综合久久| 久久久久人妻精品一区三寸蜜桃| 久久久精品久久久久特色影视| 久久综合久久综合亚洲| 亚洲αv久久久噜噜噜噜噜| 久久99中文字幕久久| 性做久久久久久免费观看 | 精品久久久无码人妻中文字幕| 久久精品国产WWW456C0M| 亚洲精品国产自在久久| 久久久精品日本一区二区三区| 久久久久久久久波多野高潮| 久久国产精品-国产精品| 欧美激情精品久久久久久久| 狠狠狠色丁香婷婷综合久久俺| 国内精品久久久久久久久| 亚洲AV无码久久精品蜜桃| 激情五月综合综合久久69| 国产精品一区二区久久国产| 久久91精品国产91| 99久久精品免费| 国产成人精品免费久久久久| 久久天天婷婷五月俺也去| 久久人人爽人人爽AV片| 久久精品国产亚洲av高清漫画| 日韩va亚洲va欧美va久久| 国内精品久久久久久久亚洲 | 国产呻吟久久久久久久92| 精品久久人人爽天天玩人人妻| 久久香蕉国产线看观看猫咪?v| 精品无码久久久久国产| www久久久天天com| 国产精品久久免费| 久久久久亚洲AV无码专区首JN| 久久综合九色综合久99|