小編給大家分享一下python中all函數(shù)怎么用,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
實例內(nèi)容:Python代碼文件test.py如下
def _local_func(): print 'local' def test(): _local_func()
通過all函數(shù)來控制import *的導(dǎo)出范圍:
__all__ = ['test'] def _local_func(): print 'local' def test(): _local_func() def test1(): _local_func()
執(zhí)行結(jié)果如下:
>>> from test import * >>> test1() Traceback (most recent call last): File "", line 1, in NameError: name 'test1' is not defined >>> test() local >>>
以上是“python中all函數(shù)怎么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!