• <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)
            久久人人爽人人爽人人片av麻烦| 国产精品久久影院| 天天影视色香欲综合久久| 无码人妻久久一区二区三区免费| 精品久久久久久成人AV| 亚洲成人精品久久| 久久久久成人精品无码中文字幕 | 99久久免费国产精品特黄| 99国产精品久久| 久久99国产一区二区三区| 99国产精品久久久久久久成人热| 品成人欧美大片久久国产欧美...| 久久综合综合久久综合| 老男人久久青草av高清| 久久国产精品久久精品国产| 精品久久人人爽天天玩人人妻| 久久这里只有精品18| 日韩va亚洲va欧美va久久| 久久国产乱子伦免费精品| 亚洲欧美另类日本久久国产真实乱对白 | 久久精品国产只有精品66| 久久综合丝袜日本网| 国产精品久久午夜夜伦鲁鲁| 思思久久99热免费精品6| 青青青国产成人久久111网站| 久久久久av无码免费网| 日韩精品无码久久一区二区三| 亚洲精品国产成人99久久| 亚洲国产精品久久电影欧美| 亚洲国产成人久久综合一区77 | 久久人妻少妇嫩草AV无码蜜桃 | 无码人妻精品一区二区三区久久| 国产精品久久久天天影视香蕉 | 人妻无码久久精品| 久久成人精品| 久久人人爽人人爽AV片| 国产精品女同一区二区久久| 久久久久中文字幕| 国内精品久久久久国产盗摄| 91久久国产视频| 午夜精品久久久久成人|