user6654733 user6654733 - 1 year ago 148
Python Question

result when __all__ is not defined in of package?

I am just learning and practicing python,on the way,i am reading about python packages and how to import into other modules or package at Modules ,I assume the following scenario ,

I have package as ,


and in no

I have not defined


what happens if i have an import statement as,

import Video.format.mkv
import Video.formats.*

Since I have already imported mkv module in first statement,what exactly happens after execution of second import statement,I didnt get the concept after reading on the mentioned link.

Answer Source

When you do

from whatever_package import *

first, if the package's hasn't been run yet, it will be run. (If you've already done import whatever_package.something_specific, the package's will have already been run.)

Then, if whatever_package.__init__ does not define an __all__ list, the import will pick up all current contents of the whatever_package object. That'll be anything defined in and any submodules that have already been explicitly imported by any code that has executed in your program. For example, if whatever_package's is empty, you do

import whatever_package.something_specific
from whatever_package import *
import whatever_package.other_thing

and no other import statements relating to whatever_package exist in your program, then the import * will pick up something_specific, but not any other submodules of whatever_package, such as other_thing.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download