Hide imported modules to interpreter

冷暖自知 提交于 2019-12-12 08:37:14

问题


I have built a module which is using a few different modules for various tasks. When I'm importing my module in IPython and listing the available functions for autocompletion, these external modules are included in that list. Is it possible to hide them in some way?


回答1:


In Python, modules can define an __all__ variable, which is a list of the names that should be imported when someone does:

from module import *

IPython can use the same variable to limit completions, though it does not do this by default. To enable this at runtime, set:

get_ipython().Completer.limit_to__all__ = True

Or to set it permanently, add to your ipython_config.py:

c.IPCompleter.limit_to__all__ = True


来源:https://stackoverflow.com/questions/19663958/hide-imported-modules-to-interpreter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!