Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import symbols starting with underscore

Tags:

python

I'm writing a simple Python library in which I have several "private" functions starting with underscore:

def _a():
    pass

def _b():
    pass

def public_interface_call():
    _a()
    _b()

This way my library users can simply do from MyLib.Module import * and their namespace won't be cluttered with implementation detail.

However I'm also writing unit tests in which I'd love to test these functions separately and simple importing truly all symbols from my module would be very handy. Currently I'm doing from Mylib.Module import _a _b public_interface_call but I wonder if there's any better/quicker/cleaner way to achieve what I want?

like image 609
Michał Góral Avatar asked Jul 20 '15 14:07

Michał Góral


1 Answers

According to docs,

There is even a variant to import all names that a module defines:
from fibo import *
...
This imports all names except those beginning with an underscore (_).

Not sure why this is the case however.

like image 67
Jet Blue Avatar answered Oct 13 '22 04:10

Jet Blue