Hide external modules when importing a module (e.g. regarding code-completion)

后端 未结 4 424
慢半拍i
慢半拍i 2020-12-09 09:11

I have several modules in one package (a kind of a toolkit), which I use in my projects. The structure looks like this:

the_toolkit:
    __init__.py
    basi         


        
4条回答
  •  无人及你
    2020-12-09 09:38

    I had the same problem, and solved it by adding a leading underscore to all my imports. It doesn't look brilliant, but it achieves what you're after.

    from __future__ import division as _division
    import numpy as _np
    import pandas as _pd
    

    Only the stuff that starts without an underscore is imported when you import the module using from .. import *. or when you use tab-completion in IPython or spyder.

提交回复
热议问题