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

            統計系統
            久久精品国内一区二区三区| 午夜不卡888久久| 欧美与黑人午夜性猛交久久久 | 国产成人综合久久综合| 欧美777精品久久久久网| 久久嫩草影院免费看夜色| 久久久久久精品无码人妻| 人人狠狠综合久久亚洲88| 久久无码AV中文出轨人妻| 97精品国产91久久久久久| 伊人久久大香线蕉综合网站| 久久国产成人精品麻豆| 久久无码AV一区二区三区| 国产精品国色综合久久| 久久99久久99精品免视看动漫| 国内精品久久久久久野外| 99久久成人18免费网站| 9999国产精品欧美久久久久久| 午夜精品久久影院蜜桃| 国产午夜福利精品久久2021| 久久无码AV一区二区三区| 亚洲国产精品久久久久婷婷软件| 中文国产成人精品久久不卡 | 久久久久久久久久久久久久| 国产精品熟女福利久久AV| 99久久久国产精品免费无卡顿| 亚洲午夜无码久久久久小说| 久久精品免费网站网| 色综合久久综精品| 国产成人无码久久久精品一| 伊人久久综合精品无码AV专区| 欧美午夜精品久久久久久浪潮| 一级做a爰片久久毛片人呢| 国产精品一区二区久久| 99999久久久久久亚洲| 久久这里只有精品18| 久久精品毛片免费观看| 久久久久亚洲AV无码永不| 久久偷看各类wc女厕嘘嘘| 无码国内精品久久人妻蜜桃| 99久久99这里只有免费费精品|