我们可以避免在我创建的模块上使用dir时显示内置插件吗?像在这种情况下,我想避免显示诸如os,sys,random,struct,time,hashlib等内置库。
>>> import endesive.pdf.cms
>>> dir(endesive.pdf.cms)
['EncodedString', 'SignedData', 'UnencryptedBytes', 'WNumberObject', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_cmath', 'backends', 'codecs', 'datetime', 'hashlib', 'io', 'pdf', 'pkcs12', 'po', 'random', 'sign', 'signer', 'struct', 'sys', 'time']
在模块中注明:
import sys
__dir__ = [x for x in globals() if x not in sys.modules]