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

            統計系統
            色天使久久综合网天天| 91精品国产乱码久久久久久| 国产欧美久久一区二区| 亚洲精品无码久久久久sm| 91精品国产色综合久久| 久久综合视频网| 国产Av激情久久无码天堂| 蜜桃麻豆www久久国产精品| 久久青草国产精品一区| 麻豆成人久久精品二区三区免费| 久久99国产精品久久| 精品久久久久中文字幕一区| 97久久超碰国产精品2021| 亚洲欧美伊人久久综合一区二区| 77777亚洲午夜久久多喷| 国产亚洲精久久久久久无码| 精品久久久久久亚洲精品| 2019久久久高清456| 婷婷伊人久久大香线蕉AV| 中文字幕热久久久久久久| 99久久免费国产精精品| 国产精品99久久99久久久| 99久久99久久| 久久精品这里只有精99品| 久久久久国产精品人妻| 国内精品九九久久久精品| 嫩草影院久久99| 久久天天躁夜夜躁狠狠躁2022 | 久久久精品一区二区三区| 色综合久久最新中文字幕| 久久久国产亚洲精品| 欧美成a人片免费看久久| 精品国产乱码久久久久久呢| 久久最新精品国产| 国内精品伊人久久久久av一坑| 久久精品草草草| 色综合合久久天天综合绕视看| 欧美久久久久久精选9999| 欧美精品九九99久久在观看| 久久国产精品波多野结衣AV| 亚洲国产成人久久精品影视|