• <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年9月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            統(tǒng)計

            • 隨筆 - 182
            • 文章 - 1
            • 評論 - 41
            • 引用 - 0

            留言簿(10)

            隨筆分類(70)

            隨筆檔案(182)

            文章檔案(1)

            如影隨形

            搜索

            •  

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

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


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            統(tǒng)計系統(tǒng)
            久久99精品综合国产首页| 久久午夜夜伦鲁鲁片免费无码影视| 亚洲色婷婷综合久久| 亚洲va久久久噜噜噜久久狠狠| 久久国产精品成人影院| 久久青草国产手机看片福利盒子| 久久久久99精品成人片三人毛片| 久久精品aⅴ无码中文字字幕不卡| 久久久久高潮毛片免费全部播放| 久久久精品日本一区二区三区| 亚洲欧美日韩中文久久| 国产综合成人久久大片91| 77777亚洲午夜久久多人| 狠狠人妻久久久久久综合蜜桃 | 麻豆一区二区99久久久久| 91精品国产高清久久久久久91| 久久AV无码精品人妻糸列| 国产精品欧美亚洲韩国日本久久| 久久久久亚洲精品无码蜜桃 | 久久人人添人人爽添人人片牛牛| 久久精品免费观看| 精品蜜臀久久久久99网站| 精品综合久久久久久98| 四虎影视久久久免费观看| 香蕉久久一区二区不卡无毒影院| 精品无码久久久久国产| 中文字幕乱码久久午夜| 久久精品青青草原伊人| 精品久久久久成人码免费动漫| 久久久久亚洲爆乳少妇无| 久久综合九色综合久99| 国产精品99久久免费观看| 无码AV波多野结衣久久| 久久天天躁狠狠躁夜夜96流白浆| 日本人妻丰满熟妇久久久久久| 色播久久人人爽人人爽人人片AV| 久久久久久午夜精品| 久久亚洲精品无码aⅴ大香| 99久久国产亚洲综合精品| 99久久国产综合精品女同图片| 亚洲国产精品高清久久久|