通过这个简单的模块:
#!/usr/bin/python
#file: foo.py
import ctypes
class Foo(ctypes.Structure):
pass
在iPython中:
In [1]: import foo
In [2]: foo.
Foo
ctypes
ctypes
是在模块内部使用的模块foo
,不应向用户显示。我们的目标是躲避ctypes
提供的自动完成功能ipython
这个解决方案太麻烦了吗?
import ctypes as __ctypes
我通常用__all__
那个。您的代码将变为:
import ctypes
# Note here
___all__ = []
class Foo(ctypes.Structure):
pass
# Note here
__all__ += ['Foo']
如果这样做from foo import *
,您只会看到Foo
(或添加到的其他内容__all__
)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句