如何避免在模块上使用dir时出现内置文件

问题描述 投票:0回答:1

我们可以避免在我创建的模块上使用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']

python python-imaging-library python-import python-packaging
1个回答
0
投票

在模块中注明:

import sys
__dir__ = [x for x in globals() if x not in sys.modules]
© www.soinside.com 2019 - 2024. All rights reserved.