• <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>

            公告

            記錄我的生活和工作。。。
            <2012年10月>
            30123456
            78910111213
            14151617181920
            21222324252627
            28293031123
            45678910

            統(tǒng)計(jì)

            • 隨筆 - 182
            • 文章 - 1
            • 評(píng)論 - 41
            • 引用 - 0

            留言簿(10)

            隨筆分類(70)

            隨筆檔案(182)

            文章檔案(1)

            如影隨形

            搜索

            •  

            最新隨筆

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            What is `if __name__ == "__main__"` for?

            轉(zhuǎn)載自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) 評(píng)論(0)  編輯 收藏 引用

            統(tǒng)計(jì)系統(tǒng)
            2021国内精品久久久久久影院| AV无码久久久久不卡蜜桃| 99久久婷婷国产一区二区| 亚洲综合婷婷久久| 亚洲国产成人久久综合区| 中文字幕无码精品亚洲资源网久久| 国产综合久久久久| 亚洲精品国产第一综合99久久| 无码人妻久久久一区二区三区| 99久久精品费精品国产| 色狠狠久久综合网| 久久伊人精品青青草原高清| 国产精品一区二区久久精品涩爱| 国产一区二区三区久久精品| 久久午夜福利无码1000合集| 久久99精品久久久久久9蜜桃| 久久精品国产久精国产一老狼| 99久久99久久久精品齐齐| 亚洲欧美日韩精品久久亚洲区 | 久久综合国产乱子伦精品免费| 热re99久久精品国产99热| 久久亚洲精品成人无码网站| 99久久亚洲综合精品成人| 成人免费网站久久久| 久久人人爽人人爽人人AV东京热| 久久久精品久久久久久| 99久久精品这里只有精品| 久久精品欧美日韩精品| 亚洲av日韩精品久久久久久a| 四虎国产精品成人免费久久| 久久久久国产一区二区三区| 99久久亚洲综合精品网站| 国产成人久久精品一区二区三区| 99蜜桃臀久久久欧美精品网站| 伊人久久亚洲综合影院| 久久99这里只有精品国产| 无码人妻久久一区二区三区蜜桃| 久久久久久免费视频| 久久久久青草线蕉综合超碰| 中文字幕日本人妻久久久免费| 性做久久久久久久|