Pyhon: the difference of "from XX import * " when XX is file created by myself or XX is python library file(like pytorch)
When i use pytorch,i am wondering why i can't import partial functions or variables from torchvision.models.vgg  using &quot;from torchvision.models.vgg import *&quot;
Like this:
from torchvision.models.vgg import *

if __name__==&quot;__main__&quot;:
    print(cfgs[&quot;A&quot;])

and
from torchvision.models.vgg import *

from typing import Union, List, Dict, Any, cast
cfgs: Dict[str, List[Union[str, int]]] = {
    'A': [64, 'M', 128, 'M', 256, 256, 'M', 512, 512, 'M', 512, 512, 'M'],
    'B': [64, 64, 'M', 128, 128, 'M', 256, 256, 'M', 512, 512, 'M', 512, 512, 'M'],
    'D': [64, 64, 'M', 128, 128, 'M', 256, 256, 256, 'M', 512, 512, 512, 'M', 512, 512, 512, 'M'],
    'E': [64, 64, 'M', 128, 128, 'M', 256, 256, 256, 256, 'M', 512, 512, 512, 512, 'M', 512, 512, 512, 512, 'M'],
}

if __name__==&quot;__main__&quot;:
    print(make_layers(cfgs[&quot;A&quot;]))

variables &quot;cfgs&quot; and function &quot;make_layers&quot; can't be found
But i could use function like &quot;vgg16_bn()&quot; which is in the same file as &quot;make_layers&quot;
from torchvision.models.vgg import *


if __name__==&quot;__main__&quot;:
    print(vgg16_bn())

I need to import like this:
from torchvision.models.vgg import cfgs,make_layers


if __name__==&quot;__main__&quot;:
    print(make_layers(cfgs[&quot;A&quot;]))

But if the file i import is created by myself like this:
b.py:
url=&quot;http&quot;

def a ():
    return True

main.py could find variable &quot;url&quot; and function &quot;a()&quot;
from b import *


if __name__==&quot;__main__&quot;:
    print(url)
    print(a())

I don't know why it happens like this,could someone explain it.Thanks!

torchvision/models/vgg.py sets this particular __all__ indicating their exported symbols:
__all__ = [
    &quot;VGG&quot;,
    &quot;vgg11&quot;,
    &quot;vgg11_bn&quot;,
    &quot;vgg13&quot;,
    &quot;vgg13_bn&quot;,
    &quot;vgg16&quot;,
    &quot;vgg16_bn&quot;,
    &quot;vgg19_bn&quot;,
    &quot;vgg19&quot;,
]

* imports (while generally discouraged) will by default expose the names in __all__ (or if __all__ is missing, any names which do not start with _)
