Time to destroy Walter: breaking modules into packages

bearophile bearophileHUGS at lycos.com
Wed Jun 5 16:08:45 PDT 2013


Andrei Alexandrescu:

> https://github.com/D-Programming-Language/dmd/pull/2139

Probably you already know the following things because they see, 
similar solutions.

Python uses "__init__.py" instead of "package.d", it can also be 
empty:
http://docs.python.org/2/tutorial/modules.html

__init__.py can also execute initialization code for the package, 
like static this() in D.

Inside __init__.py you can also define a "__all__" variable where 
you list all the modules imported when "from package import *" is 
used.

>If __all__ is not defined, the statement from sound.effects 
>import * does not import all submodules from the package 
>sound.effects into the current namespace; it only ensures that 
>the package sound.effects has been imported (possibly running 
>any initialization code in __init__.py) and then imports 
>whatever names are defined in the package. This includes any 
>names defined (and submodules explicitly loaded) by __init__.py. 
>It also includes any submodules of the package that were 
>explicitly loaded by previous import statements.<

Bye,
bearophile


More information about the Digitalmars-d mailing list