• <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 閱讀(235) 評論(0)  編輯 收藏 引用

            統計系統
            亚洲中文字幕无码久久精品1| 久久精品国产国产精品四凭| 久久人妻少妇嫩草AV无码专区| 无码AV波多野结衣久久| 99久久精品国产麻豆| 激情五月综合综合久久69| 中文字幕精品久久| 久久精品国产亚洲一区二区| 日本精品久久久久久久久免费| 久久青青草原亚洲av无码app| 亚洲v国产v天堂a无码久久| 精品久久久久久国产潘金莲| 久久乐国产综合亚洲精品| 国产精品毛片久久久久久久 | 久久最近最新中文字幕大全| 国产aⅴ激情无码久久| 久久久久99精品成人片| 久久99精品国产一区二区三区| 久久久久久精品无码人妻| 国产精品九九九久久九九| 国内精品综合久久久40p| 欧美大战日韩91综合一区婷婷久久青草 | 色婷婷综合久久久久中文| 青青热久久国产久精品 | 亚洲精品久久久www| 99久久免费国产精品| 狠狠色丁香婷婷综合久久来| 久久亚洲春色中文字幕久久久| 日产精品99久久久久久| 久久WWW免费人成一看片| 国产欧美久久久精品影院| 亚洲色欲久久久久综合网| 亚洲国产日韩欧美综合久久| 综合久久一区二区三区 | 色欲久久久天天天综合网精品| 中文字幕久久精品| 99久久99久久精品国产片果冻| 亚洲精品国产美女久久久| 久久天堂AV综合合色蜜桃网| 久久精品国产网红主播| 国产精品一区二区久久国产|